All Projects → tencentyun → Cos Js Sdk V5

tencentyun / Cos Js Sdk V5

Licence: mit
腾讯云 COS JS SDK(XML API)

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Cos Js Sdk V5

Paypal Php Sdk
PHP SDK for PayPal RESTful APIs
Stars: ✭ 2,100 (+960.61%)
Mutual labels:  sdk
Hyperdash Sdk Py
Official Python SDK for Hyperdash
Stars: ✭ 190 (-4.04%)
Mutual labels:  sdk
Js Realtime Sdk
LeanCloud Realtime Message JavaScript SDK
Stars: ✭ 193 (-2.53%)
Mutual labels:  sdk
Iot Python
Client libraries and samples for connecting to IBM Watson IoT using Python 2.7 and 3.x
Stars: ✭ 183 (-7.58%)
Mutual labels:  sdk
Flamelink
JavaScript SDK for integrating with Flamelink CMS 🔥
Stars: ✭ 186 (-6.06%)
Mutual labels:  sdk
React Native Alipay
Alipay SDK for React Native. Support RN >= 0.47.
Stars: ✭ 191 (-3.54%)
Mutual labels:  sdk
Alipay Sdk Python All
支付宝开放平台 Alipay SDK for Python
Stars: ✭ 174 (-12.12%)
Mutual labels:  sdk
Pdfxkit
A drop-in replacement for Apple PDFKit powered by our PSPDFKit framework under the hood.
Stars: ✭ 195 (-1.52%)
Mutual labels:  sdk
Objc Sdk
LeanCloud Objective-C SDK
Stars: ✭ 186 (-6.06%)
Mutual labels:  sdk
Oci Python Sdk
Oracle Cloud Infrastructure SDK for Python
Stars: ✭ 191 (-3.54%)
Mutual labels:  sdk
Meilisearch Js
Javascript client for the MeiliSearch API
Stars: ✭ 183 (-7.58%)
Mutual labels:  sdk
Msgraph Sdk Java
Microsoft Graph SDK for Java
Stars: ✭ 184 (-7.07%)
Mutual labels:  sdk
Speechtotext Websockets Javascript
SDK & Sample to do speech recognition using websockets in Javascript
Stars: ✭ 191 (-3.54%)
Mutual labels:  sdk
Ios Consent Sdk
Configurable consent SDK for iOS
Stars: ✭ 178 (-10.1%)
Mutual labels:  sdk
Pdk
The shortest path to better modules: Puppet Development Kit; Download:
Stars: ✭ 194 (-2.02%)
Mutual labels:  sdk
Cognitive Face Windows
Windows SDK for the Microsoft Face API, part of Cognitive Services
Stars: ✭ 175 (-11.62%)
Mutual labels:  sdk
Api 3.0 Php
SDK PHP da API 3.0 da Cielo
Stars: ✭ 189 (-4.55%)
Mutual labels:  sdk
Pan Os Python
The PAN-OS SDK for Python is a package to help interact with Palo Alto Networks devices (including physical and virtualized Next-generation Firewalls and Panorama). The pan-os-python SDK is object oriented and mimics the traditional interaction with the device via the GUI or CLI/API.
Stars: ✭ 194 (-2.02%)
Mutual labels:  sdk
Sdk
Library for using Grafana' structures in Go programs and client for Grafana REST API.
Stars: ✭ 193 (-2.53%)
Mutual labels:  sdk
Cognitive Face Ios
iOS SDK for the Microsoft Face API, part of Cognitive Services
Stars: ✭ 191 (-3.54%)
Mutual labels:  sdk

cos-js-sdk-v5

腾讯云 COS JS SDK(XML API

releases and changelog

Get started

一、前期准备

  1. 首先,JS SDK 需要浏览器支持基本的 HTML5 特性,以便支持 ajax 上传文件和计算文件 md5 值。
  2. COS对象存储控制台 创建存储桶,得到 Bucket(存储桶名称) 和 Region(地域名称)
  3. 控制台密钥管理 获取您的项目 SecretId 和 SecretKey
  4. 配置 CORS 规则,配置例子如下图:

cors

二、计算签名

由于签名计算放在前端会暴露 SecretId 和 SecretKey,我们把签名计算过程放在后端实现,前端通过 ajax 向后端获取签名结果,正式部署时请再后端加一层自己网站本身的权限检验。

这里提供 PHP 和 NodeJS 的签名例子,其他语言,请参照对应的 XML SDK

三、上传例子

  1. 创建 test.html,填入下面的代码,修改里面的 Bucket 和 Region。
  2. 部署好后端的签名服务,并修改 getAuthorization 里的签名服务地址
  3. 把 test.html 放在 Web 服务器下,然后在浏览器访问页面,测试文件上传
<input id="file-selector" type="file">
<script src="dist/cos-js-sdk-v5.min.js"></script>
<script>
var Bucket = 'test-1250000000';
var Region = 'ap-guangzhou';

// 初始化实例
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);
                var credentials = data.credentials;
            } catch (e) {
            }
            if (!data || !credentials) return console.error('credentials invalid');
            callback({
                TmpSecretId: credentials.tmpSecretId,
                TmpSecretKey: credentials.tmpSecretKey,
                XCosSecurityToken: credentials.sessionToken,
                StartTime: data.startTime, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
                ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000900
            });
        };
        xhr.send();
    }
});

// 监听选文件
document.getElementById('file-selector').onchange = function () {

    var file = this.files[0];
    if (!file) return;

    // 分片上传文件
    cos.sliceUploadFile({
        Bucket: Bucket,
        Region: Region,
        Key: file.name,
        Body: file,
        onHashProgress: function (progressData) {
            console.log('校验中', JSON.stringify(progressData));
        },
        onProgress: function (progressData) {
            console.log('上传中', JSON.stringify(progressData));
        },
    }, function (err, data) {
        console.log(err, data);
    });

};
</script>

webpack 引入方式

支持 webpack 打包的场景,可以用 npm 引入作为模块

npm i cos-js-sdk-v5 --save

Start Demo

1. git clone cos-js-sdk-v5 至本地
2. cd cos-js-sdk-v5
3. 修改 server 文件夹中 sts.js 或 sts.php 中的 secretId、secretKey、bucket、region 配置
4. npm run server # 用 node 启动服务
5. 浏览器输入 http://127.0.0.1:3000/ 即可进行 demo 演示

说明文档

使用例子

快速入门

接口文档

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].