【发布时间】:2016-06-21 15:46:35
【问题描述】:
我正在使用外部 API 上传个人资料照片。 http://open.convio.com/api/#teamraiser_api.uploadPersonalPhoto_method.html
这是我的代码:
@Multipart
@POST("/CRTeamraiserAPI?method=uploadPersonalPhoto")
public void uploadPersonalPhotoAsync(
@Query("fr_id") int frId,
@Part("graphic_upload_file") TypedFile graphic_upload_file,
@Query("graphic_upload_upload") boolean graphic_upload_upload,
@Query("graphic_caption") String graphic_caption,
@Header("sso_auth_token") String token,
Callback<UploadPersonalPhotoResponse> callback);
这就是我使用它的方式
public void uploadPersonalPhotoAsync(final String cacheKey, int frID, String token, String graphic_upload_file, boolean graphic_upload_upload) {
File imgFile = new File(graphic_upload_file);
TypedFile tFile = new TypedFile("image/*", imgFile);
mTeamRaiserApi.uploadPersonalPhotoAsync(frID, tFile, true, "caption", token, new Callback<UploadPersonalPhotoResponse>() {
@Override
public void success(UploadPersonalPhotoResponse uploadPersonalPhotoResponse, Response response) {
uploadPersonalPhotoResponse.lastUpdatedTime = System.currentTimeMillis();
uploadPersonalPhotoResponse.loadedFromCache = false;
uploadPersonalPhotoResponse.cacheKey = cacheKey;
EventBus.getDefault().post(new UploadPersonalPhotoEvent(uploadPersonalPhotoResponse));
}
@Override
public void failure(RetrofitError error) {
EventBus.getDefault().post(new UploadPersonalPhotoEvent(null));
}
});
}
仅更新标题。日志显示 API 要求的 Content-Type: multipart/form-data。
【问题讨论】:
标签: android image upload retrofit multipart