cffile alternative, I need to upload without form submit

谁都会走 提交于 2019-12-14 03:59:29

问题


So I want to upload a file to the server using ajax, so the form is not submitted. Cffile requres the filefield attribute, but as there is no form object passed to coldfusion that doesn't work. I can store the value entered by the user as a variable in javascript, and pass that variable to cf. How can I use this variable to upload my file? Thanks.

EDIT Solved by submitting to iframe.


回答1:


You can use the cffileupload tag (embeds a flash widget for uploading) , or take advantage of XMLHttpRequest level 2 (browser support) via the method explained here.




回答2:


Are you uploading images? You could try uploading to a canvas tag client side using javascript.

Then ajax post the base64 png encoded contents of the canvas.

Further reading and examples:

How to upload/POST multiple canvas elements

How to convert image into base64 string using javascript

Resizing an image in an HTML5 canvas

Resize image before upload, but upload synchronously (not ajax). Is it possible?

http://coding.pressbin.com/84/File-API-Resize-photo-before-upload/




回答3:


Submit the form to a hidden iframe and handle your form upload as you normally would.



来源:https://stackoverflow.com/questions/11852813/cffile-alternative-i-need-to-upload-without-form-submit

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