Coder Social home page Coder Social logo

Comments (11)

carsonxu avatar carsonxu commented on June 23, 2024

有的,近期优化这个demo。

  1. 使用 https://github.com/tencentyun/qcloud-cos-sts-sdk 获取临时密钥
  2. 再用 https://github.com/tencentyun/cos-nodejs-sdk-v5 生成签名

from cos-js-sdk-v5.

slince avatar slince commented on June 23, 2024

@carsonxu 有php版本的吗

from cos-js-sdk-v5.

carsonxu avatar carsonxu commented on June 23, 2024

PHP:

  1. 用这个代码获取临时密钥 https://github.com/tencentyun/cos-js-sdk-v5/blob/master/server/sts.php
  2. 用 SDK 获取签名:https://github.com/tencentyun/cos-php-sdk-v5

from cos-js-sdk-v5.

slince avatar slince commented on June 23, 2024

@carsonxu

本项目readme上的这段获取授权和qcloud文档上的有什么区别,两端代码分别请求的后端是sts.php和sts-auth.php; 所用到的参数也不完全相同,我是需要按照官方文档上的来还是本项目的demo来

var cos = new COS({
    getAuthorization: function (options, callback) {
        var url = '../server/sts.php';
        var xhr = new XMLHttpRequest();
        xhr.open('GET', url, true);
        xhr.onload = function (e) {
            try {
                var data = JSON.parse(e.target.responseText);
            } catch (e) {
            }
            callback({
                TmpSecretId: data.credentials && data.credentials.tmpSecretId,
                TmpSecretKey: data.credentials && data.credentials.tmpSecretKey,
                XCosSecurityToken: data.credentials && data.credentials.sessionToken,
                ExpiredTime: data.expiredTime,
            });
        };
        xhr.send();
    }
});

https://cloud.tencent.com/document/product/436/9067

   xhr.onload = function (e) {
                var AuthData;
                try {
                    AuthData = JSON.parse(xhr.responseText)
                } catch (e) {}
                if (AuthData && AuthData.Authorization) {
                    callback(null, {
                        Authorization: AuthData.Authorization,
                        XCosSecurityToken: AuthData.XCosSecurityToken,
                    });
                } else {
                    console.error(AuthData);
                    callback('获取签名出错');
                }
            };
            xhr.onerror = function (e) {
                callback('获取签名出错');
            };

from cos-js-sdk-v5.

slince avatar slince commented on June 23, 2024

@carsonxu

我按照cloud,tencent。com 的上面的例子去写,得到这么个结果:

<?xml version='1.0' encoding='utf-8' ?>
<Error>
	<Code>RequestTimeTooSkewed</Code>
	<Message>The difference between the request time and the current time is too large.</Message>
	<Resource>phpdish-1251726071.cos.ap-beijing.myqcloud.com</Resource>
	<RequestId>NWIxZjVlMGNfZDI4NWQ2NF8yMDY2MV8yYjE3M2I=</RequestId>
	<TraceId>OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTBjYzE2MjAxN2M1MzJiOTdkZjMxMDVlYTZjN2FiMmI0NGYxMTg3ODZiZjg0NjU3NjRlMmYxZWMxZmQwZDM2NGU=</TraceId>
</Error>

麻烦给看下是什么原因。

from cos-js-sdk-v5.

yuanfangluo avatar yuanfangluo commented on June 23, 2024

有的,近期优化这个demo。

  1. 使用 https://github.com/tencentyun/qcloud-cos-sts-sdk 获取临时密钥
  2. 再用 https://github.com/tencentyun/cos-nodejs-sdk-v5 生成签名

你好, 后端获取临时秘钥再返回给客户端, 客户端直接拿着秘钥就可以调用云存储的接口上传图片了, 那这里面的生成签名是干嘛用的?为啥还要生成签名

from cos-js-sdk-v5.

carsonxu avatar carsonxu commented on June 23, 2024

@luoshuisheng 这里是前端如果不想用SDK,不方便计算签名,就可以让服务端计算好签名给前端用。

from cos-js-sdk-v5.

yuanfangluo avatar yuanfangluo commented on June 23, 2024

为啥JavaScript的sdk里面有jquery, 建议sdk不要使用第三方库

from cos-js-sdk-v5.

carsonxu avatar carsonxu commented on June 23, 2024

这里是包含了 jquery.ajax.js 库,打包后不依赖 jQuery 也可以运行。

from cos-js-sdk-v5.

yuanfangluo avatar yuanfangluo commented on June 23, 2024

我在reactnative使用不了,说是有jquery,而reactnative是可以使用ajax的

from cos-js-sdk-v5.

yuanfangluo avatar yuanfangluo commented on June 23, 2024

@luoshuisheng 这里是前端如果不想用SDK,不方便计算签名,就可以让服务端计算好签名给前端用。

node怎么计算签名给前端用?

from cos-js-sdk-v5.

Related Issues (20)

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.