Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading file as stream in play framework 2.0
    primarykey
    data
    text
    <p>I'm writing a play 2.0 java application that allows users to upload files. Those files are stored on a third-party service I access using a Java library, the method I use in this API has the following signature:</p> <pre><code>void store(InputStream stream, String path, String contentType) </code></pre> <p>I've managed to make uploads working using the following simple controller:</p> <pre><code>public static Result uploadFile(String path) { MultipartFormData body = request().body().asMultipartFormData(); FilePart filePart = body.getFile("files[]"); InputStream is = new FileInputStream(filePart.getFile()) myApi.store(is,path,filePart.getContentType()); return ok(); } </code></pre> <p>My concern is that this solution is not efficient because by default the play framework stores all the data uploaded by the client in a temporary file on the server then calls my uploadFile() method in the controller. </p> <p>In a traditional servlet application I would have written a servlet behaving this way:</p> <pre><code>myApi.store(request.getInputStream(), ...) </code></pre> <p>I have been searching everywhere and didn't find any solution. The closest example I found is <a href="https://stackoverflow.com/questions/11468768/why-makes-calling-error-or-done-in-a-bodyparsers-iteratee-the-request-hang-in-p">Why makes calling error or done in a BodyParser&#39;s Iteratee the request hang in Play Framework 2.0?</a> but I didn't found how to modify it to fit my needs.</p> <p>Is there a way in play2 to achieve this behavior, i.e. having the data uploaded by the client to go "through" the web-application directly to another system ?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload