Question

I am getting a "multipart/mixed" response to an http request that I need to parse. One part of the response is a pdf file which I need to save to disk. Is there any library that will do this for me?

Was it helpful?

Solution

Here is what I did in groovy. Needed java mail library:

//... get reader from response, can use response.success callback in http.request
ByteArrayDataSource ds = new ByteArrayDataSource(new ReaderInputStream(reader), "multipart/mixed");
MimeMultipart multipart = new MimeMultipart(ds);
BodyPart part = multipart.getBodyPart(1);
file = new File('/../../path/filename.pdf')
file << part.content

OTHER TIPS

Have you tried retrieving it from the request?

 CommonsMultipartFile file = request.getFile('myFile') //File
 def offerId = params.offerId //Standard Param
 def index = params.idx //Standard Param

This corresponds to a form input like below:

<input class="invDocUpload" id="invFileUpload" type="file" name="myFile" size="40"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top