agrafix / Spock

Another Haskell web framework for rapid development
https://www.spock.li
679 stars 56 forks source link

How does files/UploadedFile work #66

Closed elfeck closed 8 years ago

elfeck commented 8 years ago

Hi,

I am wondering how files and UploadedFile work, especially, where the files "/tmp/webenXXXX.buf" is stored in the filesystem. I was trying to decipher the src in Spock but it I don't have a lot of knowledge of WAI. Can someone explain/point me to the right doc or src if no doc is available?

Thanks!

agrafix commented 8 years ago

The uploaded files are handled here: https://github.com/agrafix/Spock/blob/c13fc9bcade9afe11b008a1c20d9498bcee34d7b/src/Web/Spock/Internal/Wire.hs#L266 using the https://hackage.haskell.org/package/wai-extra-3.0.13/docs/Network-Wai-Parse.html package and the tempFileBackend.

elfeck commented 8 years ago

Ah okay, thanks! So it seems that WAI uses getTemporaryDirectory from System.Directory. But I can't find the temporary file which is supposed to be there. Any idea why? Or more explicitly: When does the temporary file get deleted again?

agrafix commented 8 years ago

The file will only live while the request is being processed and removed shortly after.

elfeck commented 8 years ago

Is the file then hold in-memory or does it get moved somewhere else?

agrafix commented 8 years ago

No, it's your responsibility to persist the file by for example copying it to a different location.

elfeck commented 8 years ago

Okay, so after I call files, I need to deal with it or else it vanishes. Makes sense. You can close this issue this is correct. Thanks for your help!

agrafix commented 8 years ago

No worries, glad I could help!