开发者社区> 问答> 正文

用OSSFile上传照片,回调了onSuccess,但实际文件没有上传成功

用OSSFile上传照片,回调了onSuccess,但实际文件没有上传成功,


有谁遇到这个问题,分享一下怎么解决

展开
收起
wuhou 2015-06-15 15:44:06 5997 0
2 条回答
写回答
取消 提交回答
  • 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;
        }
    2015-06-15 16:00:53
    赞同 展开评论 打赏
  • 把相关的资料贴出来。
    2015-06-15 15:57:20
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载