Question

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!

Was it helpful?

Solution

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 to POST a file) which will call the entity.c servlet (which reports everything about the POST entity 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.c to 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.c can also be called to analyse any kind of request, not only multipart/form-data encodings, and not only POST requests (it also demonstrates PUT and DELETE).

A last note: I have also modified the code to make sure that BOTH the URI parameters and a POST/PUT entity are listed in the servlet argc/argv main().

This allows things like: POST /?blog/user/1245/day/24 where all you need to access user=1245 and day=24 (as well as the entity) is to read argv[].

Hope that this will help you in your projects!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top