一直显示这个{ "error": "app/accesskey is not found" }

歌尽桃花
  • 1
新手上路,请多包涵

我的这个是对的呀 我还去看了一下
var http = require('http')
var fs = require('fs')
var url = require('url')
var port = process.argv[2]
var qiniu = require('qiniu')

if(!port){
console.log('node server.js 8888 ')
process.exit(1)
}

var server = http.createServer(function(request, response){
var parsedUrl = url.parse(request.url, true)
var pathWithQuery = request.url
var queryString = ''
if(pathWithQuery.indexOf('?') >= 0){ queryString = pathWithQuery.substring(pathWithQuery.indexOf('?')) }
var path = parsedUrl.pathname
var query = parsedUrl.query
var method = request.method

/ 从这里开始看,上面不要看 /

console.log( pathWithQuery)

if(path==='/uptoken'){

response.statusCode = 200
response.setHeader('Content-Type', 'text/json;charset=utf-8')
response.setHeader('Access-Control-Allow-Origin', '*')
response.removeHeader('Date')

var config = fs.readFileSync('./qiniu-key.json')
config = JSON.parse(config)

let {accessKey, secretKey} = config;
var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
var options = {
  scope: 'music-qn',
};
var putPolicy = new qiniu.rs.PutPolicy(options);
var uploadToken=putPolicy.uploadToken(mac);
response.write(`
{
  "uptoken": "${uploadToken}"
}
`)
response.end()

}else{

response.statusCode = 404
response.setHeader('Content-Type', 'text/html;charset=utf-8')
response.end()

}

})

server.listen(port)
console.log( port + ' http://localhost:' + port)

回复
阅读 407
1 个回答
卿小鱼
  • 1
新手上路,请多包涵
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

logo
七牛云问答
子站问答

非结构化静态文件的高速稳定安全云存储平台

访问社区
宣传栏