Skip to content

update demo #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ Session.vim
# Files that might appear on external disk
.Spotlight-V100
.Trashes
node_modules
.idea
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

1. 安装依赖库

`npm install express qiniu`
`npm install `

2. 获取示例程序源代码:

Expand All @@ -22,7 +22,7 @@

3. 编辑 `nodejs-ajax-upload-example/app/server.js` 文件, 修改其中配置项 `qiniu.conf.ACCESS_KEY` 和 `qiniu.conf.SECRET_KEY` 的值。参考 [应用接入:获取Access Key 和 Secret Key](http://docs.qiniutek.com/v2/api/auth/#app-access)

4. 在 `nodejs-ajax-upload-example/app` 目录下运行命令:`node server.js`
4. 在 `nodejs-ajax-upload-example/app` 目录下运行命令:`node index.js`

5. 用浏览器打开 `nodejs-ajax-upload-example/public/index.html` 进行体验

Expand Down
41 changes: 0 additions & 41 deletions app/server.js

This file was deleted.

60 changes: 60 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Created by youxiachai on 14-2-12.
*/
var express = require('express'),
app = express(),
http = require("http");

var qiniu = require("qiniu");

// 配置密钥
qiniu.conf.ACCESS_KEY = '';
qiniu.conf.SECRET_KEY = '';

var opts = {
// scope: "yet_another_bucket", // 可以是 "<bucketName>" 或 "<bucketName>:<key>"
expires: 15552000
// callbackUrl: "http://www.example.com/notifications/qiniurs", // 可选
// callbackBodyType: "application/x-www-form-urlencoded", // 可选
};

var uploadPolicy = new qiniu.rs.PutPolicy('yet_another_bucket');
uploadPolicy.expires = 15552000;


var uploadToken = uploadPolicy.token();

app.use(express.static(__dirname + '/public'));

app.set('port', 8125);


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', '*');

res.json({
code : 200,
data : {
url : 'http://up.qiniu.com/',
bucket : 'stock',
token : uploadToken
}
})


});



http.createServer(app).listen(app.get('port'), function () {
console.log('env: ' + process.env.NODE_ENV);
console.log('port: ' + process.env.PORT);
console.log('Express server listening on port ' + app.get('port'));
});
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "nodejs-ajax-upload-example",
"version": "0.0.0",
"description": "一个基于 [七牛云存储](http://www.qiniutek.com) [NodeJS SDK](https://github.com/qiniu/nodejs-sdk) 开发的 Ajax 上传([jQuery-File-Upload](http://blueimp.github.com/jQuery-File-Upload/))示例程序。",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/youxiachai/nodejs-ajax-upload-example.git"
},
"author": "youxiachai",
"license": "MIT",
"bugs": {
"url": "https://github.com/youxiachai/nodejs-ajax-upload-example/issues"
},
"homepage": "https://github.com/youxiachai/nodejs-ajax-upload-example",
"dependencies": {
"qiniu": "~6.1.1",
"express": "~3.4.8"
}
}
Loading