How to fake ajax file upload?

北城余情 提交于 2019-12-23 12:26:45

问题


I've an upload form I would like to populate with a file, in particular an image.

My understanding is that I need to create a File object to put in the FileList of the relative form. Currently the image I have is in the data URI format "data:image/png;base64,..." but I can change that.

If that is true how do I create the correct File object from an image and add it to the FileList? If it is not do you suggest a better solution?


回答1:


Use a regular form and target it to an iframe with display set as none.

<form id="my_form" enctype="multipart/form-data" action="upload_handler.php" method="POST" target="upload_target">
   <input name="uploadfile" type="file" />
   <input type="submit" value="Upload File" />
</form>
<iframe id="upload_target" name="upload_target" style="display:none;"></iframe> 


来源:https://stackoverflow.com/questions/6396682/how-to-fake-ajax-file-upload

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