Amazon S3 POST, event when done?
I'm using Amazon S3 with a simple project, when the user uploads a file, I first use an XMLHTTPRequest
to send the details to my database, then trigger the form POST that uploads the file straight to S3.
What I can't quite work out though is how to tell when the upload is done so I can update the display properly (I'm cheating at the moment and just updating the display once it's saved in the database, you can barely tell for small uploads, but obviously a problem in the long run.)
The S3 server appears to "cancel navigation" once the upload is complete, so the page doesn't reload - are there any events that are fired that I can use to detect when the upload is complete?
EDIT: I'm using the form code from here http://s3.amazonaws.com/doc/s3-example-code/post/post_sample.html just add开发者_StackOverflow社区ed an onsubmit to the form that fires the XMLHTTPRequest to my own server before the form gets posted to amazon.
Amazon S3 will redirect to the url specified in the success_action_redirect
field or if that's not specified, it returns an empty document with the status code specified in success_action_status
.
On completion of the POST, the user is redirected to the location that you specified in the success_action_redirect field. If Amazon S3 cannot interpret the URL, it ignores the success_action_redirect field.
If success_action_redirect is not specified, Amazon S3 returns the empty document type specified in the success_action_status field.
If the POST fails, Amazon S3 displays an error and does not provide a redirect.
See the AWS docs for more details.
Amazon S3 won't trigger any kind of event, but your XMLHTTPRequest code should be able to trigger a callback when S3 returns an HTTP 200 status code.
If S3 isn't returning a successful response code, it's quite possible that S3 doesn't know that your upload is complete. Are you sending a Content-Length
header as part of your request?
精彩评论