MultipartUploadRequest(上传期间出错)安卓10

huangapple go评论68阅读模式
英文:

MultipartUploadRequest (Error during upload) android 10

问题

以下是您要翻译的内容:

我在多个项目中使用过这个,从未遇到过任何错误,但当我尝试在安卓10上使用时,在上传尝试后不久,在上传过程中出现错误。如果有任何人也尝试过这种方式:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

我的代码:

try {
    String uploadId = UUID.randomUUID().toString();

    Toast.makeText(this, path, Toast.LENGTH_SHORT).show();
    //创建多部分请求

    new MultipartUploadRequest(this, Constants.UPLOAD_URL)
            .setMethod("POST")
            .addFileToUpload(path, "image") //添加文件
            .addHeader("x-amz-acl", "bucket-owner-full-control")
            .addParameter("UserID", userId) //向请求添加文本参数
            .setAutoDeleteFilesAfterSuccessfulUpload(false)
            .setUsesFixedLengthStreamingMode(true)
            .setNotificationConfig(new UploadNotificationConfig())
            .setMaxRetries(5)
            .startUpload(); //开始上传

} catch (Exception exc) {
    Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show();
}

控制台错误:

I/System.out: [okhttp]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [okhttp] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out: [socket]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [socket] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out: [okhttp]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [okhttp] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out: [socket]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [socket] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out: [okhttp]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [okhttp] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out: [socket]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [socket] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
英文:

I have used this in multiple projects never got any error but when i tried this in android 10 its attempt to upload but after some time it gives error during upload. If there is any one who

tried this way as well:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

`My code:

 try{
  String uploadId = UUID.randomUUID().toString();

        Toast.makeText(this, path, Toast.LENGTH_SHORT).show();
        //Creating a multi part request


        new MultipartUploadRequest(this, Constants.UPLOAD_URL)
                .setMethod("POST")
                .addFileToUpload(path, "image") //Adding file
                .addHeader("x-amz-acl", "bucket-owner-full-control")
                .addParameter("UserID", userId) //Adding text parameter to the request
                .setAutoDeleteFilesAfterSuccessfulUpload(false)
                .setUsesFixedLengthStreamingMode(true)
                .setNotificationConfig(new UploadNotificationConfig())
                .setMaxRetries(5)
                .startUpload(); //Starting the upload

    } catch (Exception exc) {
        Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show();
    }`

Console Error:
I/System.out: [okhttp]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [okhttp] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out: [socket]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [socket] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out: [okhttp]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [okhttp] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out: [socket]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [socket] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out: [okhttp]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [okhttp] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils
I/System.out: [socket]:check permission begin!
W/System: ClassLoader referenced unknown path: system/framework/mediatek-cta.jar
I/System.out: [socket] e:java.lang.ClassNotFoundException: com.mediatek.cta.CtaUtils

答案1

得分: 3

我经过大量的研究找到了答案,原来是我的疏忽。如果能帮助到他人,可以在你的清单文件中加入以下内容:

<android:requestLegacyExternalStorage="true">
英文:

I got the answer after lot of research it was my own mistake if it can save someone's day use this in your Manifest:

'<android:requestLegacyExternalStorage="true">'

huangapple
  • 本文由 发表于 2020年8月18日 13:05:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63462169.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定