How to use the qiniu.digestauth function in qiniu

To help you get started, we’ve selected a few qiniu examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github qiniudemo / nodejs-ajax-upload-example / app / server.js View on Github external
var express = require('express');
var qiniu = require('qiniu');

// required, type your ACCESS_KEY and SECRET_KEY here
qiniu.conf.ACCESS_KEY = '';
qiniu.conf.SECRET_KEY = '';

// will be removed after all io-nodes ready support CORS
qiniu.conf.IO_HOST = 'http://ionode-my-1.qbox.me';

// specify a common bucket name for storage your files
var bucket = 'MY_UPLOADS_BUCKET';

var conn = new qiniu.digestauth.Client();
var rs = new qiniu.rs.Service(conn, bucket);

var app = express.createServer();

app.get('/putauth.json', function(req, res){

    // our front-end isnot serve by node server, all of them are static files
    // so we need output response headers for CORS
    // or you can change to use template engine for render pages
    res.header('Pragma', 'no-cache');
    res.header('Cache-Control', 'no-store, no-cache, must-revalidate');
    res.header('X-Content-Type-Options', 'nosniff');
    res.header('Access-Control-Allow-Origin', '*');

    // output response body as json format
    rs.putAuth(function(resp){