Giter Club home page Giter Club logo

Comments (12)

dengdai1993 avatar dengdai1993 commented on June 11, 2024

请问有示例吗

let COS = require('../utils/cos-react-native-sdk-v5.js');
initCos() {
this.cos = new COS({
getAuthorization: function (options, callback) {
let body = "Method=" + options.Method + "&Key=" + options.Key
fetch(constants.host + constants.workspace + 'api/txcos/sts.php', {
method: 'GET',
}).then((response) => response.json()).then(
(responseJson) => {
// alert(JSON.stringify(responseJson))
let data = responseJson.data
callback({
TmpSecretId: data.credentials && data.credentials.tmpSecretId,
TmpSecretKey: data.credentials && data.credentials.tmpSecretKey,
XCosSecurityToken: data.credentials && data.credentials.sessionToken,
ExpiredTime: data.expiredTime,
});
})
.catch((error) => {
alert(error);
});
}
});
}

this.cos.postObject({
Bucket: this.Bucket,
Region: this.Region,
Key: key,
FilePath: result.uri
}, function (err, response) {
if (err) {
alert("上传失败")
return;
}
result.remoteUrl = key;

    });

from react-native-tencent-cos-v5.

dengdai1993 avatar dengdai1993 commented on June 11, 2024

没有加上传进度,只会回调成功失败

from react-native-tencent-cos-v5.

notbucai avatar notbucai commented on June 11, 2024

没有加上传进度,只会回调成功失败

https://github.com/tencentyun/cos-xml-react-native

大哥这个库用过吗,他小文件打包后只有进度没有回调

from react-native-tencent-cos-v5.

dengdai1993 avatar dengdai1993 commented on June 11, 2024

没。。。就是因为没找到好用的,才自己改了下本来是个给js用的库

from react-native-tencent-cos-v5.

notbucai avatar notbucai commented on June 11, 2024

没。。。就是因为没找到好用的,才自己改了下本来是个给js用的库

没有进度是因为 rn XMLHttpRequest 的问题吗

from react-native-tencent-cos-v5.

dengdai1993 avatar dengdai1993 commented on June 11, 2024

因为我懒得加了T_T

from react-native-tencent-cos-v5.

notbucai avatar notbucai commented on June 11, 2024

因为我懒得加了T_T

能给思路嘛,嘻嘻嘻

from react-native-tencent-cos-v5.

dengdai1993 avatar dengdai1993 commented on June 11, 2024

if (filePath.startsWith('data')) {
let file = dataURLtoFile(filePath);
cosFormData.append('file', file);
console.log(JSON.stringify("cosFormData:" + file))
fetch(url,{
method :"POST",
body: cosFormData,
headers: {
"Content-Type": "multipart/form-data; boundary="
}
}).then((response) => {
// alert("上传成功" + response);
console.log("上传成功2" + response);
// callback(true);
callback(null, {statusCode: 200, headers: response.header}, response.data);
}).catch((error) => {
// alert("上传失败" + error);
console.log("上传失败2" + error);
callback(false);
});
} else {
let file = {uri: filePath, type: 'multipart/form-data', name: 'image.jpeg'};
cosFormData.append('file', file);
console.log(JSON.stringify(cosFormData))
fetch(url,{
method :"POST",
body: cosFormData,
headers: {
"Content-Type": "multipart/form-data"
}
}).then((response) => {
console.log("上传成功1" + response);
callback(null, {statusCode: 200, headers: response.header}, response.data);
}).catch((error) => {
console.log("上传失败1" + error);
callback(false);
});
}

from react-native-tencent-cos-v5.

dengdai1993 avatar dengdai1993 commented on June 11, 2024

我替换了这里,大概是第2716行,为了省事换成了fetch传的,所以没进度

from react-native-tencent-cos-v5.

notbucai avatar notbucai commented on June 11, 2024

爱了爱了,我先试试,可能后面还得麻烦你

from react-native-tencent-cos-v5.

dengdai1993 avatar dengdai1993 commented on June 11, 2024

我是做android和ios原生开发的,对js其实不是很熟。。。你先试试吧

from react-native-tencent-cos-v5.

notbucai avatar notbucai commented on June 11, 2024

谢谢,已经搞定了

from react-native-tencent-cos-v5.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.