【发布时间】:2017-09-07 05:51:46
【问题描述】:
界面:
@Multipart
@POST("emp/passportupload")
Single<ApiResponse> uploadPassportImage(@Query("passportnumber") String passportNumber, @Part MultipartBody.Part file);
调用api:
File file = new File(model.getImage().getPath());
if (!file.exists()) return null;
RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file);
MultipartBody.Part filePart = MultipartBody.Part.createFormData(ApiConstant.PICTURE_UPLOAD_PARAM, file.getName(), requestBody);
dataService.uploadPassportImage(map, filePart)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread());
我正在使用此方法将图像上传到服务器,但服务器无法将其验证为图像,因此给了我这样的响应
“提供的文件不是有效图片。请提供 PNG/JPG 文件”
但是,我已经通过邮递员上传了相同的图像文件,并且成功了。这是请求:(注意:passportnumber 是一个参数,而不是表单数据)
【问题讨论】:
标签: android retrofit2 image-uploading