您好试试这个,如果有帮助,但我用改造2,
摇篮
compile 'com.squareup.retrofit2:retrofit:2.0.2'
接口
public static interface FileUploadService {
@Multipart
@POST(HttpConstants.FILEUPLOADJSON1)
Call<Result> uploadImage(@Part MultipartBody.Part file, @Part("stdID") int stdID);
}
呼叫
RaytaApi service = RaytaServiceClass.getApiService();
File file = new File(imagePath);
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part body =
MultipartBody.Part.createFormData("uploaded_file", file.getName(), requestFile);
Call<Result> resultCall=service.uploadImage(body,INT_STDID);
final Result[] result = {new Result()};
resultCall.enqueue(new Callback<Result>() {
@Override
public void onResponse(Call<Result> call, Response<Result> response) {
Log.v("@@@WWE","Respnse");
}
}
@Override
public void onFailure(Call<Result> call, Throwable t) {
Log.v("@@@WWE","Failure ");
Log.v("@@@WWE","MEssage "+t.getMessage());
}
});
对于完整的例子全球化志愿服务青年,请访问 https://github.com/pratikvyas1991/NetworkingExample-master
为什么不从AWS s3服务上传文件,而不是使用翻新 –
它是否发生在REST客户端中? –
@AbdulKawee我没有得到你想说的。 – Ammar