0

I am currently creating a form that involves a file uploader. Currently my form is fine just using multipart and post but later on in future iterations it will be necessary for the form to be posted with ajax in order to edit the image before submitting the form.

I have seen a lot of things about multiple files like jquery-file-upload and swf and php with uploadify and a whole host of non IE 7+ solutions. However those are not going to work for this specific project and I am really just looking for the bare bones nothing fancy to have to deal with just sends the image data to an endpoint.

What is the best way to do this in a way that can support all browsers.

=====EDIT=====

I havent tested this completely yet but this solution seems good to me https://github.com/francois2metz/html5-formdata

BillPull
  • 6,853
  • 15
  • 60
  • 99

2 Answers2

1

Fine Uploader is a library that provides the ability to support cross-browser uploading. Ajax/xhr post requests are used for all browsers that support the file api. Otherwise, a form-based upload method is used. No flash is used or needed. This is all transparent to the user. Check out fineuploader.com for more details.

Ray Nicholus
  • 19,538
  • 14
  • 59
  • 82
-1

You can't send file through AJAX request this is just impossible. If you use HTML5 File API that would work but as you stated in your question you need to support old browsers. So I think you either have to use flash (uploadify uses flash as well) or you don't have any other option.

You can have a look at this question/answer:

jQuery Ajax File Upload

Community
  • 1
  • 1
Alex Rashkov
  • 9,833
  • 3
  • 32
  • 58
  • Is there any graceful degradation techniques to using the HTML5 File API when supported. – BillPull Nov 28 '12 at 22:49
  • This answer is not accurate. You certainly can send files via ajax, assuming the browser supports the file api. – Ray Nicholus Nov 29 '12 at 05:49
  • 1
    @RayNicholus my answer is correct I've mentioned the File API but it's not supported by older versions and BillPull is after IE7 + solution. So I've said all of the in my answer. – Alex Rashkov Nov 29 '12 at 10:45
  • 1
    @inifinity You said that you cannot send a file via Ajax. This is not correct. The original poster is after a cross-browser solution. The best solution would involve XHR for browsers that support the File API, and form-based uploads for browsers that do not. You mentioned in your answer that flash must be used, which is also not correct. – Ray Nicholus Nov 29 '12 at 14:41