認證0級講師
This is what I wrote @Part("image"; filename="image.png" ") RequestBody image
Map<String, RequestBody> photoRequestBodyMap = new HashMap<>();
photoRequestBodyMap.put("Content", RequestBody.create(MediaType.parse("text/plain"), et_body.getText().toString()));
for (int i = 0; i < picList.size(); i++) {
File file = new File(picList.get(i));
RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
String key = "image\";filename=\"" + file.getName();
photoRequestBodyMap.put(key, requestBody);
} catch (Exception e) {
}
}
netApiInterface
.postMoment(photoRequestBodyMap)
I am like this.
There are many opinions on the Internet about the key to be used when uploading images.
On my side, the actual test is that String key = "image";filename="" + file.getName(); works
Method annotations only use POST, parameter annotations only use BODY, and MultipartBody is constructed separately for uploading.
Retrofit2.0’s support for uploading files is not that simple, you should get familiar with okhttp
If you are using Retrofit2.0, then the Part annotation should be followed by MultipartBody.Part instead of RequestBody
http://m.blog.csdn.net/article/details?id=51511493 This is using okhttp as the background is php receiving
I also succeeded using httpclient, but when using retrofit, I still need to pass the token, and it never succeeded