I'm trying to upload an image with uploading bytes of Google Photos API .
So here is my request with OkHttp3:
Request request = new Request.Builder()
.addHeader("Authorization", "Bearer " + token)
.addHeader("Content-type:", "application/octet-stream")
.addHeader("X-Goog-Upload-Content-Type:",mimeType)
.addHeader("X-Goog-Upload-Protocol:", "raw")
.url("https://photoslibrary.googleapis.com/v1/uploads")
.post(requestBody) // how to build request body?
.build();
the documentation says: "In the request body, include the binary of the file:"
media-binary-data
What does it means?
For a given file, I assume that it is:
byte[] data = FileUtils.readFileToByteArray(new File(myPath));
But how do you build this requestBody with data array?
EDIT I already tried :
MediaType mType = MediaType.parse("application/octet-stream; charset=utf-8");
RequestBody requestBody = RequestBody.create(mType,new File(path));
Exception :
okhttp3.internal.http2.StreamResetException: stream was reset: PROTOCOL_ERROR
Thank you in advance for putting me on the track!