1

I am using Java (Android) to attempt to upload a file to a web server, using HttpURLConnection as recommended. I have had difficulties sending data as a POST request in the past but successfully achieved it after a few hours. This data was simple JSON data so conversion was not of major concern and I used a buffered writer to achieve the goal.

Now I would like to upload real files using multipart/form-data and am expecting a mix of different encodings to be passed of which, binary, is unsupported by both OutputStreamWriter (which only takes string or char[] args) and BufferedWriter (which only allows similar args).

I will need to send a mixture of binary and textual data to a server and am wondering, what is the best way to do this?

I will need to use the raw OutputStream to send bytes but will this conflict with OutputStreamWriter + BufferedWriter layers when it comes time to send char arrays?

Or perhaps should I convert the UTF8 text to binary using a specific method and send it all using byte arrays?

Thank you for any help provided

Patrick Sturm
  • 393
  • 1
  • 13

1 Answers1

0

I have decided, that for a small amount of overall bytes (a few MB), it would probably just be easier to use the outputstream and convert strings to byte arrays.

Although this is more inefficient in terms of memory (would have loved buffered IO), it is far more simple and while the app remains simple, it is the way to go for now.

Patrick Sturm
  • 393
  • 1
  • 13
  • The app would be even simpler if you use a library what takes care of the complexities. – Andreas May 13 '18 at 02:50
  • I have already taken care of said "complexities". I personally find writing a bit of code easier compared to managing libraries and being new to Android and Java and Android Studio, but comfortable with HTTP, I have found it easier to simply write the code myself. – Patrick Sturm May 13 '18 at 02:53