0
我以前使用的Apache瓶坯文件上传:文件上传不与改造工作
FileBody fileBody = new FileBody(new File(path), mimeType);
FormBodyPart formBodyPart = new FormBodyPart("partName", fileBody);
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart(formBodyPart);
...
这将成功上传的文件与“零件名称”
交换零件名称改装:
public interface UploadService {
@Multipart
@PUT("/somepath/{id}/upload")
Call<ResponseBody> upload(@Path("id") String id, @Part("partName") RequestBody file);
}
var id = 123;
UploadService service = retrofit.create(UploadService.class);
File file = new File(path);
RequestBody requestBody = RequestBody.create(MediaType.parse(mimeType), file);
Response<ResponseBody> response = service.upload(id, requestBody).execute();
请求的partName未设置。我究竟做错了什么?
我的答案在http://stackoverflow.com/questions/33932916/how-to-post-an-image-to-server-in-android/33952163#33952163使用OkHttp,但是,国际海事组织,也许它的逻辑可以帮助你一点点 – BNK
非常感谢。我可以尝试找出改造后出现的问题。最糟糕的情况就是使用okhttp作为解决方法。 – lostintranslation
IMO,你可以在'Headers.of(“Content-Disposition”,“form-data; name = \”file \“; filename = \”ic_launcher.png \“”)检查,因为我的web服务(Asp .Net Web API),当android客户端没有在这里设置'filename'时,web服务并不认为这是多部分请求 – BNK