改造 - 上传图片

问题描述 投票:0回答:2

我无法通过改造上传图片。

我的改造服务界面:

@Multipart
@Headers({
        "Content-Type: application/json"
})
@POST("upload_photo")
Call<ResponseBody> uploadPhoto(@Part MultipartBody.Part filePart);

致电服务:

MultipartBody.Part filePart = MultipartBody.Part.createFormData("photo", fileName, RequestBody.create(MediaType.parse("image/png"), bitmapByteArray));
Call<ResponseBody> call = service.uploadPhoto(filePart);

问题是Web服务找不到具有键/名称qazxsw poi的部件,并返回发送的图像为NULL。

photo

android post retrofit image-uploading
2个回答
0
投票

0
投票
@Multipart
@POST("upload_photo")
Observable<ResponseBody> uploadPhoto(@Part("photo") RequestBody photo);
//////////////////////////////////////////////////////////////////////////////
//pass it like this
File file = new File("/storage/emulated/0/Download/Corrections 6.jpg");
RequestBody requestFile =
        RequestBody.create(MediaType.parse("multipart/form-data"), file);

// MultipartBody.Part is used to send also the actual file name
MultipartBody.Part body =
        MultipartBody.Part.createFormData("image", file.getName(), requestFile);

service.uploadPhoto(body);
© www.soinside.com 2019 - 2024. All rights reserved.