I’m trying to upload an image file with XMLHttpRequest and FormData API to my G-WAN server but I can’t retrieve the file contents.Here is the output in h_entities:
-----------------------------75940917410019849751723987620 Content-Disposition: form-data; name="test_param" test_value
-----------------------------75940917410019849751723987620 Content-Disposition: form-data; name="uploadedFile"; filename="test.png" Content-Type: image/png PNG
“Content-type” is multipart/form-data. Has anyone managed to upload files to G-WAN? I couldn’t find an example. Thanks!
I have spent the last hours to write a dedicated example for G-WAN v3.10+ called
entity.html(a form with a[browse]button toPOSTa file) which will call theentity.cservlet (which reports everything about thePOSTentity and lists its first 1,000 bytes).The first thing that your G-WAN version 3.3 will hit is the POST entity size limit – and you will get an HTTP error 413 (request entity too large).
I wrote a servlet example called
entity_size.cto show how to modify this limit (this can be done in a handler or in a servlet, and at any time).The second thing that you would have to do (and which is done automatically with G-WAN v3.10+) is to load any missing part of the entity that was not already loaded with the HTTP request (in v3.3 this would require a handler playing with the return codes to read more until all is loaded).
These two points were recurring questions (on the now defunct forum) so that was time to give an example.
So, unless you are very courageous (and are willing to follow the above indications), you have understood that it’s probably better to wait for v3.10 which will come later this month: it will do the job for you and you will have a couple of tested examples to learn from.
Note that
entity.ccan also be called to analyse any kind of request, not onlymultipart/form-dataencodings, and not onlyPOSTrequests (it also demonstratesPUTandDELETE).A last note: I have also modified the code to make sure that BOTH the URI parameters and a
POST/PUTentity are listed in the servletargc/argv main().This allows things like:
POST /?blog/user/1245/day/24where all you need to accessuser=1245andday=24(as well as the entity) is to readargv[].Hope that this will help you in your projects!