Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read File from HttpRequest #85

Open
safar opened this issue Nov 15, 2016 · 2 comments
Open

Read File from HttpRequest #85

safar opened this issue Nov 15, 2016 · 2 comments
Labels

Comments

@safar
Copy link

safar commented Nov 15, 2016

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
Copy link
Contributor

pron commented Nov 15, 2016

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants