Snap binary files upload -


i need understand file uploading process snap.

given form:

<form id="form" action="/files/upload" method="post" enctype="multipart/form-data">   <input type="file" id="files" name="files[]" multiple />   <button type="submit"  onclick="handlefiles(e)">upload</button> </form> 

do use same functions getpostparams process binary files or use functions snap.util.fileuploads?

i need upload , save binary files pdf in database. database driver accept bytestring store binary file.

i went through snap.util.fileuploads not need. not sure how process in handler?

thanks.

edit

with irc managed come below construct. think should close correct?? well, compiles , dumps file mongodb. can read back. although don't quite understand enumerators , iteratee stuff ...

handlefiles :: apphandler () handlefiles =   [file] <- handlemultipart defaultuploadpolicy $ \part ->     content <-  liftm bs.concat el.consume     return content   let b = ["file" =: binary file]   r <- eitherwithdb $ insert "tests" b   either (error . show) (const $ return () ) r 

use snap.util.fileuploads. it's quite tricky file uploading right without leaving open security vulnerabilities. fileuploads module has been designed in mind.

the docs describe handlefileuploads pretty well. "reads uploaded files temporary directory , calls user handler process them." supply handler type:

[(partinfo, either policyviolationexception filepath)] -> m 

handlefileuploads stores incoming files on disk subject policy specify. calls handler , passes list of files handled.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -