I don’t have the code available right now, but I’ll describe my situation and post code later on :). Basically, my problem is with uploading image to server via POST (from Java desktop application / client). I found some discussions here on this matter, but it either included using org.apache.commons.httpclient classes, and I have most of the code implemented using URLConnection class, OR with bugs in it. Check this selected answer to see what I followed in as much detail as possible: Using java.net.URLConnection to fire and handle HTTP requests
Anyways, I created php script on my local server that handles form with file upload. I checked it from one static html that was created along with .php. I then checked it without file upload, and it works ok.
It also works ok when I send plain text file. This looks like a problem related to encoding. Maybe some strange character is breaking my transfer?
As I said, I’ll include code if necessary later today, but I’m interested in your opinions / experience related to encoding images when sending via POST. Should I do something else, that’s not being mentioned in the link above.
QUESTION: do I need to use some kind of encoding to actual data when sending binary file in multipart message via http post?
Sorry for no code right now.
Cheers
As for your question: yes, you need to encode the file.
I would use HttpClient for this as it takes care of all those things for you. No need to reinvent the wheel. See How to upload a file using Java HttpClient library working with PHP for code.