At a guess, I'd say that the file might be under a different key than
"image1". You can use this little function to see what file names are being
passed to you: http://play.golang.org/p/fLK98v_P1k
What follows are my random piece of advice for file uploads, feel free to
ignore everything after this point.
Instead of using FormFile, I suggest expanding the snippet I posted above
to do what you want. req.FormFile (and the backing req.ParseMultipartForm)
have a concept of "maxMemory", where upto maxMemory bytes are stored in
memory, and the rest go onto temporary files on disk. If you are writing a
typical web upload scenario, then this doesn't really do what you want.
With a web upload scenario, you have a max upload size (to prevent DOS
attacks), but you just want to disallow files larger than that size. With
the behaviour that ParseMultipartForm has, the user can still upload large
files, they just get buffered onto disk. Now, I hear you saying that you
could merely put a limit on the total size of the POST, but that is
unnecessarily limiting. Consider the social network case, where you want to
allow users to upload an album, with each picture being a maximum of 2MB,
and an album having upto 1024 photos. You'd have to set your max memory
limit to 2GB, which lets malicious users create large quantities of
temporary files on disk. I claim that the streaming snippet is much more
robust, and is not even that much more code.
Using the streaming snippet lets you support the scenario above without
buffering all the files in-memory, or writing other files to temporary
storage, so that your memory (and disk) usage is not a function of
user-controlled things (i.e. the size of the files they upload). If you use
a combination of an io.MultiWriter, a simple CountingWriter implementation,
and an io.LimitedReader, you can SHA-512 the file(s) as you stream them to
disk, limit the size per file, give an error when a single file goes over
(but still continue processing the rest of the files), and support
arbitrary number of files per upload.
Anyways, I've rambled on long enough, carry on.
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to email@example.com.
For more options, visit https://groups.google.com/groups/opt_out.