如何使用Retrofit2中带有@Part的数组将图像上传到服务

时间:2019-01-28 21:50:18

标签: java android web-services multipartform-data

我试图将图像上传到服务器没有成功,我看到了许多使用@Multipart进行操作的方法,这是使用我进入image/*解析的RequestBody进行操作的正确方法,但是我出现错误503,该错误仅在格式不同的格式不是jpg和png时才出现,我尝试了很多方法,但我不知道我的错误在哪里,因为我使用的是上载没有问题的文档所使用的相同方法。

@Multipart
@POST(Constants.Retrofit.CONVERT_IMAGE)
Call<List<ConvertImageResponse>> convertImageToURL(@Part MultipartBody.Part file);

RequestBody requestFile = RequestBody.create(MediaType.parse("image/*"), uriString);
MultipartBody.Part mFile = MultipartBody.Part.createFormData("file[]", myFile.getName(), requestFile);

ApiServices mServices = Instance.getRetrofitInstanceMagento().create(ApiServices.class);
        Call<List<ConvertImageResponse>> call = mServices.convertImageToURL(mFile);

通过此操作,我从服务获得503响应,并且我的变量uriString获取图像所在的uri的数据,我也必须已经使用multipart/form-data,但结果是相同的。

当我直接使用文件而不是uriString时,出现以下错误

okhttp3.internal.http2.ConnectionShutdownException

总而言之,问题是我无法以一种或另一种方式上传图像,希望您能对我有所帮助 我必须强调file是一种数据数组

0 个答案:

没有答案