nodejs七牛图片上传成功name返回为null。

nodejs七牛图片上传成功name返回为null。

var qiniu = require("qiniu");

var bucket = 'family';
var options = {
    scope: bucket,
    callbackUrl: "http://tribe.aladada.com/qiniuUploadSuccess",
    callbackBody:'{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}',
    callbackBodyType: 'application/json'
};

var accessKey = '';
var secretKey = '';
var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);

var putPolicy = new qiniu.rs.PutPolicy(options);
var uploadToken=putPolicy.uploadToken(mac);

var config = new qiniu.conf.Config();
// 空间对应的机房
config.zone = qiniu.zone.Zone_z0;
// 是否使用https域名
//config.useHttpsDomain = true;
// 上传是否使用cdn加速
//config.useCdnDomain = true;
// var localFile = "C:/Users/daniel/pictures/Windows 照片查看器墙纸.jpg";
var localFile = "../public/image/aabbcc.jpg";
var formUploader = new qiniu.form_up.FormUploader(config);
var putExtra = new qiniu.form_up.PutExtra();
var key='my-nodejs-logo.png';
// 文件上传
formUploader.putFile(uploadToken, key, localFile, putExtra, function(respErr,respBody,respInfo) {
    if (respErr) {
        throw respErr;
    }

    if (respInfo.statusCode == 200) {
        console.log(respInfo);
        console.log(respBody);
    } else {
        console.log(respInfo.statusCode);
        console.log(respBody);
    }
});`

结果图片描述

阅读 2.2k
1 个回答

您好,请问使用的nodejs版本是否是最新的。建议您更新到最新的nodejs的sdk在试试

推荐问题
logo
七牛云问答
子站问答
访问
宣传栏