主要是直接输入内容并且保存到七牛
var qiniu = require('qiniu'); var fs = require('fs'); // 初始化ak,sk qiniu.conf.ACCESS_KEY = '*******'; qiniu.conf.SECRET_KEY = '*******'; var key = "test1.txt"; var putPolicy = new qiniu.rs.PutPolicy('diary:' + key); var token = putPolicy.token(); fs.writeFile(key, "hello world!好的,你好", function(err) { if(err) { return console.log(err); } console.log("The file was saved!"); uploadFile(key); }); // 上传至七牛 function uploadFile(key) { qiniu.io.putFile(token, key, key, null, function(err, ret) { if (!err) { console.log(ret.key, ret.hash, ret.persistentId); } else { console.log(err) } }); } // 获取下载路径 function getDownload(key) { var policy = new qiniu.rs.GetPolicy(); var url = "http://diary.website.com/" + key; var downloadUrl = policy.makeRequest(url); console.log(downloadUrl); } getDownload("123456.jpg"); --------------------- 作者:白鼠闹东京 来源:CSDN 原文:https://blog.csdn.net/sbt0198/article/details/54572553 版权声明:本文为博主原创文章,转载请附上博文链接!