android retrofit上传二进制流 byte[] img
问题已经解决:publicstaticCall<Bean>upload(UploadApiapi,byte[]img){Map<String,Object>params=...
问题已经解决:
public static Call<Bean> upload(UploadApi api,byte[] img) {
Map<String, Object> params = new HashMap<>();
RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), img);
return api.upload(params,requestBody);
}
@Multipart
@POST("upload")
Call<Bean> upload(@QueryMap Map<String, Object> maps, @Part("img\"; filename=\"img.jpg\"")RequestBody img);
MediaType.parse("multipart/form-data") 对应 @Multipart 展开
public static Call<Bean> upload(UploadApi api,byte[] img) {
Map<String, Object> params = new HashMap<>();
RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), img);
return api.upload(params,requestBody);
}
@Multipart
@POST("upload")
Call<Bean> upload(@QueryMap Map<String, Object> maps, @Part("img\"; filename=\"img.jpg\"")RequestBody img);
MediaType.parse("multipart/form-data") 对应 @Multipart 展开
展开全部
以下宽物氏是图片上传方慎散式:
接口写法:
Java code?
1
2
3
@Multipart
@POST("/user/addLicenseInfo")
void addLicenseInfo(@QueryMap Map<String, Object> options, @Part("蚂核file") TypedFile file, Callback<JsonElement> response);
实现写法:
Java code?
1
2
3
4
5
API api = mRegisterActivity.createAPI();
Map<String, Object> options = new HashMap<String, Object>();
options.put("mobile",photoNumber);
TypedFile typedImage = new TypedFile(getMIMEType(pictureFile), pictureFile);
api.addLicenseInfo(options,typedImage,new Callback<JsonEleme
接口写法:
Java code?
1
2
3
@Multipart
@POST("/user/addLicenseInfo")
void addLicenseInfo(@QueryMap Map<String, Object> options, @Part("蚂核file") TypedFile file, Callback<JsonElement> response);
实现写法:
Java code?
1
2
3
4
5
API api = mRegisterActivity.createAPI();
Map<String, Object> options = new HashMap<String, Object>();
options.put("mobile",photoNumber);
TypedFile typedImage = new TypedFile(getMIMEType(pictureFile), pictureFile);
api.addLicenseInfo(options,typedImage,new Callback<JsonEleme
追问
TypedFile typedImage = new TypedFile(getMIMEType(pictureFile), pictureFile);
您好,这句话pictureFile是字节流吗?能提供下getMIMEType方法吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询