在Android 8+设备上MultipartUploadRequest上传失败上传期间出错

问题描述

我对MultipartUploadRequest有问题。具有较低api的设备上的所有功能都可以运行,但是当设备具有android 8或更高版本时,当我要将文件上传到服务器时,它会一直显示错误消息(“上传过程中出现错误”)。在装有Android 8的设备上,它开始发送,但是当进度达到100%时,它给出了错误(在装有Android 9的设备上,它甚至没有启动,开始上传时出错)。我以为一切都是由于缺少前台服务的通知引起的,但添加时仍然会出现问题。

我看到了类似这样的主题MultipartUploadRequest (Error during upload) android 10),但是它对我没有帮助,因为我使用的是api 18-28,而我使用的是android 9 file upload (MultipartUploadRequest) error,但是我已经获得了此权限。 / p>

我的代码

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,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();后,它转到onError。

我正在使用此lib的3.4.2版本(https://github.com/gotev/android-upload-service)。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)