Closed cvaught closed 8 years ago
What is the error you see with the new code?
There isn't an error. Instead just no data is returned. On Nov 23, 2015 4:17 PM, "Jon Stevens" notifications@github.com wrote:
What is the error you see with the new code?
— Reply to this email directly or view it on GitHub https://github.com/lookfirst/convert/issues/3#issuecomment-159084927.
Have you confirmed by looking at the server logs that data is being sent to the server?
What I'm getting at is that the way to debug this is to break down the communication between the client and the server into a series of steps and then go through those steps to confirm that data is being transferred correctly. I don't know the magic answer here, so I'll need you to go through the steps to solve the problem. =)
So the code above is correct. I'm still having an issue to where it isn't working but it appears to be due some kind of configuration issue. Still trying to find the problem. The reason I updated some dependencies was due to finally switching to a maven based project which made me realize the deprecated methods so I fixed those and then I noticed it wasn't working. I just went back to my non-maven project, updated the http mime dependency, changed the code to the above and everything works.
Thanks for the quick responses today.
I've been using this ever since App Engine removed support for converting PDFs to images. It has been awesome to use. But I was recently updating my dependencies and it appears HttpMultipart is now deprecated and instead MultipartEntityBuilder should be used. I have tried to get this working but for the life of me I can't seem to have any success.
Here is my code:
MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMimeSubtype("subType"); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); builder.setCharset(Charset.forName("UTF-8")); builder.setBoundary("bound"); builder.addBinaryBody("upload", pdfData, ContentType.create("application/pdf"), filename); builder.addTextBody("convert", "pdf:png"); builder.addTextBody("args", "-resize 300x400 -background white -flatten");
HttpEntity entity = builder.build();
URL url = new URL(HTTP_HOST); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=\"bound\""); connection.setRequestProperty("Authorization", "Basic " + encoded); connection.setConnectTimeout(TIMEOUT); connection.setReadTimeout(TIMEOUT); connection.setDoOutput(true); connection.connect();
OutputStream os = connection.getOutputStream(); entity.writeTo(os); byte[] result = IOUtils.toByteArray(connection.getInputStream());
Any help would be greatly appreciated.