I am looking for an HTML 5 AJAX library / framework for uploading files directly to Amazon S3. The goal is to not upload attachments to the web server (since it blocks the web server when transferring them to Amazon). I understand that this should be possible with XDomainRequest , but I cannot figure out how to do this.
I am running ruby-on-rails and wanted to give the downloaded file a temporary name (using the UUID) that will be sent back to the web server so that the file can later be renamed and integrated using paperclip.
Any ideas? Is this something that jQuery can handle? Flash is not an option for this project. Thanks!
Edit:
I managed to get the main position, but I still have problems. I'm not quite sure which headers are required, or how to encode the required Amazon parameters in the request (can I put them in the request header?). Here is my progress:
const XMLHTTPFactories = [ function () { return new XDomainRequest(); }, function () { return new XMLHttpRequest(); }, function () { return new ActiveXObject("Msxml2.XMLHTTP"); }, function () { return new ActiveXObject("Msxml3.XMLHTTP"); }, function () { return new ActiveXObject("Microsoft.XMLHTTP"); }, ]; var xhr = null; for (var i = 0; i < XMLHttpFactories.length; i++) { try { xhr = XMLHttpFactories[i](); break; } catch (exception) { continue; } } $(this).change(function () { for (var i = 0; i < this.files.length; i++) { var file = this.files[i]; xhr.open(settings.method, settings.url, true); xhr.setRequestHeader("Cache-Control", "no-cache"); xhr.setRequestHeader("Content-Type", "multipart/form-data"); xhr.setRequestHeader("Access-Control-Allow-Origin", "*") xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xhr.setRequestHeader("X-File-Name", file.fileName); xhr.setRequestHeader("X-File-Size", file.fileSize); xhr.send(file); }
Edit:
After additional updates, I managed to get the following error:
XMLHttpRequest cannot load http://bucket.s3.amazonaws.com/ . The origin of http://local.app is not allowed by Access-Control-Allow-Origin.
I downloaded the crossdomain.xml file, which allows access from a wildcard (*) domain. Not sure how to proceed ...
Edit:
After you have done more research, I begin to think that JavaScript POST may not be possible for S3. Should I send a message to an EC2 instance before translating? I could provide a micro-instance, but I would prefer to go directly to S3 if possible! Thanks!
Edit:
I posted a question on Amazon forums and did not receive any feedback. For cross-references, another post can be found here: https://forums.aws.amazon.com/message.jspa?messageID=206650#206650 .