Search code examples
erlangmochiwebyaws

Mochiweb : Reading a file as it is uploaded


I want to be able to read a file just as it is being uploaded by the user, i.e. I want to read the incoming stream of bytes from the user's browser.. Is that possible with Mochiweb? If not, where do I need to look/modify?

If something else easier exists on Yaws, that will also be great. Thanks.


Solution

  • Yup.

    Mochiweb is all pretty low level, so you get access to that pretty easily.

    Check out the mochiweb_request module. mochiweb_request:stream_body/3 is probably what you're after. Not sure how it handles file attachments sent as multipart requests, but that shouldn't be too difficult to figure out.