How to fake ajax file upload?

2019-06-26 00:13发布

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条回答
Fickle 薄情
2楼-- · 2019-06-26 00:43

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> 
查看更多
登录 后发表回答