Coder Social home page Coder Social logo

nodejs-sdk's Introduction

Node wrapper for Qiniu Resource (Cloud) Storage API

该 SDK 适用于 NodeJS 0.4.7 及其以上版本,基于 七牛云存储官方API 构建。若您的服务端是一个基于 NodeJS 编写的网络程序,使用此 SDK ,能让您以非常便捷地方式将数据安全地存储到七牛云存储上。以便让您应用的终端用户进行高速上传和下载,同时也使得您的服务端更加轻盈。

安装

npm install qiniu

获取 ACCESS_KEY 和 SECRET_KEY

要对接七牛云存储服务,您需要七牛云存储服务端颁发给您的 ACCESS_KEYSECRET_KEYACCESS_KEY 用于标识客户方的身份,在网络请求中会以某种形式进行传输。SECRET_KEY 作为私钥形式存放于客户方本地并不在网络中传递,SECRET_KEY 的作用是对于客户方发起的具体请求进行数字签名,用以保证该请求是来自指定的客户方并且请求本身是合法有效的。使用 ACCESS_KEY 进行身份识别,加上 SECRET_KEY 进行数字签名,即可完成应用接入与认证授权。

您可以通过如下步骤获得 ACCESS_KEYSECRET_KEY

  1. 开通七牛开发者帐号
  2. 登录七牛开发者自助平台,查看 ACCESS_KEY 和 SECRET_KEY

获取到 ACCESS_KEYSECRET_KEY 之后,您就可以参考下面的示例代码进行接入使用了。

使用

SDK 使用文档参考:http://docs.qiniutek.com/v2/sdk/nodejs/

示例程序

var qiniu = require("qiniu");

qiniu.conf.ACCESS_KEY = '<YOUR_ACCESS_KEY>';
qiniu.conf.SECRET_KEY = '<YOUR_SECRET_KEY>';

var conn = new qiniu.digestauth.Client();
var rs = new qiniu.rs.Service(conn, "<YOUR_CUSTOM_BUCKET_NAME>");

// uploading by the server side

var key = "test.js";
var friendlyName = key;

// uploading script self
rs.putFile(key, null, __filename, function(resp) {
    console.log("\n===> PutFile result: ", resp);
    if (resp.code != 200) {
        return;
    }

    // get information and downalod url of the uploaded file
    rs.get(key, friendlyName, function(resp) {
        console.log("\n===> Get result: ", resp);
        if (resp.code != 200) {
            return;
        }
    });
});


// uploading by the client side

rs.putAuth(function(resp) {
    console.log("\n===> PutAuth result: ", resp);
    if (resp.code != 200) {
        return;
    }
    // then send the resp.data.url to your clients
    // for more details, see: http://docs.qiniutek.com/v2/api/io/#rs-PutAuth
});

贡献代码

  1. Fork
  2. 创建您的特性分支 (git checkout -b my-new-feature)
  3. 提交您的改动 (git commit -am 'Added some feature')
  4. 将您的修改记录提交到远程 git 仓库 (git push origin my-new-feature)
  5. 然后到 github 网站的该 git 远程仓库的 my-new-feature 分支下发起 Pull Request

许可证

Copyright (c) 2012 qiniutek.com

基于 MIT 协议发布:

nodejs-sdk's People

Contributors

xushiwei avatar why404 avatar

Watchers

saighost avatar James Cloos avatar

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.