I've been rooting around through the net/http code and haven't quite come up with a solution for this. I need to perform a multipart POST re开发者_如何学Cquest, which I have already figured out, but it would be really nice to inject a callback periodically in the upload so I could increment a progress bar. Does anyone know a way to get code to execute every X number of bytes sent during an HTTP post?
It doesn't look like you're using Rails, but I think that the easiest way to do this is from the client.
In a browser setting, you can do this either with Flash (SWFUpload) or to only provide a progress bar to new browsers using new XMLHttpRequest stuff (upload still works in older browsers... just no progress bar).
It works a little differently than you're describing, but the difference is very small. You're talking about asking the server how much data it has actually saved. These methods only report how much data has been sent to the server.
- SwfUpload (Flash implementation with progress bar) - http://www.swfupload.org/
- Implementation of AJAX upload with progress bar and nice fallback in older browsers - http://valums.com/ajax-upload/
- Documentation on how AJAX upload works with newer browsers - https://developer.mozilla.org/en/using_xmlhttprequest#Monitoring_progress
精彩评论