用OSSFile上传照片,回调了onSuccess,但实际文件没有上传成功
Re用OSSFile上传照片,回调了onSuccess,但实际文件没有上传成功
public void doUploadFile(String path, String filename, final boolean isCallBack) throws Exception {
OSSFile ossFile = new OSSFile(sampleBucket, filename);
ossFile.setUploadFilePath(path + filename, 'image/jpg');
ossFile.enableUploadCheckMd5sum();// 开启上传md5校验
if (isCallBack) {
Message myMessage = new Message();
myMessage.what = 3;
myMessage.obj = 0;
handler.sendMessage(myMessage);
}
ossFile.uploadInBackground(new SaveCallback() {
@Override
public void onProgress(String arg0, int arg1, int arg2) {
if (isCallBack) {
Message myMessage = new Message();
myMessage.what = 1;
myMessage.obj = (int) ((double) arg1 / (double) arg2 * 100);
handler.sendMessage(myMessage);
}
}
@Override
public void onFailure(String arg0, OSSException arg1) {
Message myMessage = new Message();
myMessage.what = 4;
myMessage.obj = 100;
handler.sendMessage(myMessage);
}
@Override
public void onSuccess(String arg0) {
if (ImageFunction.checkUrlFile(Variable.aliyuncs_url + CacheData.appInfo.getBucketName() + '/' + arg0)) {
if (isCallBack) {
Message myMessage = new Message();
myMessage.what = 2;
myMessage.obj = 100;
handler.sendMessage(myMessage);
}
} else {
Message myMessage = new Message();
myMessage.what = 4;
myMessage.obj = 100;
handler.sendMessage(myMessage);
}
}
});
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int position = (Integer) msg.obj;
int what = (Integer) msg.what;
if ((what == 1) && (updateProgress != null)) {
updateProgress.refreashProgress(position);
} else if ((what == 2) && (updateProgress != null)) {
updateProgress.sendSuccess();
} else if ((what == 3) && (updateProgress != null)) {
updateProgress.startUpload();
} else if ((what == 4) && (updateProgress != null)) {
updateProgress.sendError();
}
}
};
public void setUpdateProgress(sendPhotoProgressInterfacer updateProgress) {
this.updateProgress = updateProgress;
}
赞0
踩0