hufans / react-native-alioss

aliyun oss for react native
MIT License
16 stars 8 forks source link

Android: error about verifyCRC64 when asyncUpload to OSS #7

Closed emclab closed 2 years ago

emclab commented 2 years ago

My app is React Native 0.66.3 on Big Sur platform running android emulator. Here is the code of init:

import { AliyunOSS } from "rn-alioss";
const saveOSS = async (bucket_name, objkey, filePath) => {     
        return (new Promise((resolve) => {
            console.log("in saveOSS : ");  //<<==this console output was in output screen
            AliyunOSS.asyncUpload(bucket_name, objkey, filePath).then( (res) => {
                resolve(true);
            }).catch((error)=>{
                //try again after 50 ms
                setTimeout(()=> {
                    AliyunOSS.asyncUpload(bucket_name, objkey, filePath).then((res) => {
                        //console.log("Success : ", res);
                        resolve(true);
                    }).catch((error1)=>{
                        resolve(false);
                    })
                }, 20);
            })
        }));
    };

        var bucket_name = "oss-bucket";  //<<<
            const configuration = {
                maxRetryCount: 3,  
                timeoutIntervalForRequest: 30,
                timeoutIntervalForResource: 24 * 60 * 60
            };

            const STSConfig = {
                AccessKeyId:storageAccessInfo.accessKeyId,
                SecretKeyId:storageAccessInfo.accessKeySecret,
                SecurityToken:storageAccessInfo.securityToken
            }
            const endPoint = 'https://oss-cn-hangzhou.aliyuncs.com';  //<<<

            //STS init, twice 
            try {
                AliyunOSS.initWithSecurityToken(STSConfig.SecurityToken,STSConfig.AccessKeyId,STSConfig.SecretKeyId,endPoint,configuration);
            } catch(err1) {
                setTimeout(()=>{
                    AliyunOSS.initWithSecurityToken(STSConfig.SecurityToken,STSConfig.AccessKeyId,STSConfig.SecretKeyId,endPoint,configuration);
                }, 10);
            };
....
try {
                    let res = await saveOSS(bucket_name, objkey, filePath);  //<<== filePath starts with file:///... for local image picked
} catch (err) {
...
}

On real device (android 10 Huawei p30), the app crash after starting upload to OSS. However the module works on IOS emulator with failure sometimes. Here is the error screen shot when running on Android emulator (android 8.1 with android studio 2021).

Screen Shot 2022-01-28 at 2 30 25 PM Screen Shot 2022-01-28 at 2 39 14 PM

hufans commented 2 years ago

If you have CRC64 issues please add to the init config codeOSSinit = { maxRetryCount: number; timeoutIntervalForRequest: number; timeoutIntervalForResource: number; VerifyCRC64:boolean; };

emclab commented 2 years ago

Shall I make VerifyCRC64:false? Or either true or false will work.

emclab commented 2 years ago

Tried both VerifyCRC64:true and false and they throw the same error.

emclab commented 2 years ago

BTW the issue shall be allowed to be reopened again if issue still remains.

emclab commented 2 years ago

Here is the working one : verifyCRC64:true/false. Both true or false works in my case.