android 8+设备上的multipartuploadrequest上载失败(上载时出错)

xyhw6mcr  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(284)

我对多重任务有问题。所有东西都在API较低的设备上运行,但是当设备有android 8或更高版本时,当我想将文件上传到服务器时,它会一直给我错误(“上传时出错”)。在android 8的设备上,它开始发送,但当进度达到100%时,它会给出错误(在android 9的设备上,它甚至不会启动,开始上传时出错)。我以为一切都是因为前台服务缺少通知造成的,但添加时问题仍然出现。
我看到了类似的主题,比如这个(multipartupladRequest(上传时出错)android 10),但它对我没有帮助,因为我使用的是api 18-28,还有这个android 9文件上传(multipartupladRequest)错误,但我已经有了这个权限。
我的代码:

private void uploadMultipart(final Context context){

        try{
            MultipartUploadRequest uploadRequest = new MultipartUploadRequest(context,SERVER_URL)
                    .setUtf8Charset()
                    .setMethod("POST")
                    .setMaxRetries(0)
                    .setNotificationConfig(new UploadNotificationConfig())
                    .addFileToUpload(zipDir.getAbsolutePath()+"/"+emailAddress+".zip","file")
                    .setDelegate(new UploadStatusDelegate() {
                        @Override
                        public void onProgress(Context context, UploadInfo uploadInfo)
                        {
//                            Log.i("Progress", String.valueOf(uploadInfo.getProgressPercent()));
                            asyncResponse.returnProgress(uploadInfo.getProgressPercent());
                        }

                        @Override
                        public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, Exception exception) {
//                            Log.i("error","error");
                            asyncResponse.returnHttpStatus(50);
                        }
                        @Override
                        public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {

                            asyncResponse.returnHttpStatus(serverResponse.getHttpCode());
//                            Log.i("SEND DONE", String.valueOf(serverResponse.getHttpCode()));
                        }

                        @Override
                        public void onCancelled(Context context, UploadInfo uploadInfo) {
//                            Log.i("Progress","Cancelled");
                        }
                    });
                   .addParameter("email",emailAddress);

                    // For Android > 8, we need to set an Channel to the UploadNotificationConfig.
                    // So, here, we create the channel and set it to the MultipartUploadRequest
            mNotificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);

            // Android O requires a Notification Channel.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                CharSequence name = "SPN";
                // Create the channel for the notification
                NotificationChannel mChannel =
                        new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT);

                // Set the Notification Channel for the Notification Manager.
                mNotificationManager.createNotificationChannel(mChannel);
            }
            uploadRequest.startUpload();

        }
        catch (Exception e){
            errorInSending=true;

        }
    }

我在asynctask中运行这个函数(在doinbackground函数中)。打电话后 uploadRequest.startUpload(); 它去了一个错误。
我正在使用这个lib的3.4.2版本(https://github.com/gotev/android-upload-service).

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题