is it possible to set the contents (data) of a file upload input via javascript?

浪尽此生 提交于 2019-12-06 10:36:09

问题


i am using html5 canvas to alter an image. i would like to be able to use the resulting canvas image data to send to the server using the same file upload field. (alternately, it could be by adding a new field to the existing form).

i have converted the image to a Blob, but it seems that the only way to send this type of data to the server is using FormData, which requires its own (separate) XMLHttpRequest. this is not desirable for me.

(context: i am trying to essentially hijack any arbitrary file input field in any arbitrary form on a page. consequently, i do not want to alter the method the form is submitted and i would also like to avoid changing anything on the server side as well. basically, i think the only way to do this would be to re-use or replace the file field. probably not possible, but i thought i would ask.)

来源:https://stackoverflow.com/questions/11482391/is-it-possible-to-set-the-contents-data-of-a-file-upload-input-via-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!