1

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.

Jeff Fabiny
  • 325
  • 2
  • 15

3 Answers3

2

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.

Community
  • 1
  • 1
Todd Sharp
  • 3,207
  • 2
  • 19
  • 27
0

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/

Community
  • 1
  • 1
Mike Causer
  • 8,196
  • 2
  • 43
  • 63
0

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

Jeff Fabiny
  • 325
  • 2
  • 15