puniverse / comsat

Fibers and actors for web development
docs.paralleluniverse.co/comsat
Other
598 stars 103 forks source link

Read File from HttpRequest #85

Open safar opened 7 years ago

safar commented 7 years ago

I have mixed form with text and file input fields which is being processed by a WebActor. I have to be able to read text input fields by their key and File contents from the same message.

I have used code below to read sent request using WebActor using Netty:

if (message instanceof HttpRequest) {
      final HttpRequest msg = (HttpRequest) message;
      logger.info("msg: {}", new String(msg.getByteBufferBody().array(),
            Charset.forName("UTF-8")));
}

this is the output

------WebKitFormBoundaryRJbBHRjR4HKByqsl
Content-Disposition: form-data; name="test_key"

test_value
------WebKitFormBoundaryRJbBHRjR4HKByqsl
Content-Disposition: form-data; name="file"; filename="accounts.png"
Content-Type: image/png

�PNG

\��q$Z5��X� ߀DDD$;��L�ܝm8|�J
... omitted binary gibberish 
��    IEND�B`�
------WebKitFormBoundaryRJbBHRjR4HKByqsl--

Are we intended to parse these messages manually? Is there a method which can read File part of HttpRequest directly which I'm unaware of? What is the easiest way to read a file from a multipart HttpRequest received by a WebActor?

pron commented 7 years ago

Multipart parsing is currently not natively supported by Web Actors. You have a few options: you can either parse the buffer using a library such as Apache Commons FileUpload, or you can handle the upload in a different servlet resource and use Servlet 3's native support for multipart.

Should Web Actors support multipart natively? Is it a right fit for the actor paradigm? Is using a separate servlet for uploads not a good solution?

circlespainter commented 7 years ago

I don't see big advantages offered by specifically supporting multipart in Web Actors. @safar Why would you like to use Web Actors specifically in this case and won't some other method do? For example Netty seems to have a dedicated handler.