-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I POST a image binary in retrofit 2.0 beta 2? #1217
Comments
Hello, can you provide dump of network calls? You can do this in multiple ways. One of suggestions to use proxy network tool Charles. Or simply use OkHttp logging interceptor. Full request and response info may help to understand your issue. |
i have the same problem before,i think you can write Service like this: |
Please check #1063 |
@LintonLin How can I specify picture_name.png in |
Here is my http interceptor logging:
|
Final Solutions
@POST("trip/{tripId}/media/photos")
Call<MediaPost> postEventPhoto(
@Path("eventId") int tripId,
@Header("Authorization") String accessToken,
@Query("direction") String direction,
@Body RequestBody photo);
InputStream in = new FileInputStream(new File(media.getPath()));
byte[] buf;
buf = new byte[in.available()];
while (in.read(buf) != -1);
RequestBody requestBody = RequestBody
.create(MediaType.parse("application/octet-stream"), buf);
Call<MediaPost> mediaPostCall = tripApiService.postTripPhoto(
tripId,
((GlobalInfo) getApplicationContext()).getApiAccessToken(),
direction,
requestBody); |
I'm trying to POST a image binary to my server, here is my code:
API Service
API Call
I've tried to use
MediaType.parse("image/*")
orMediaType.parse("application/octet-stream")
, but the server always returned No MIME found. I'm sure that my file exists!!How can I fix it?? Thanks.
The text was updated successfully, but these errors were encountered: