我正在使用节点js来上传quickblox中的内容。以下是我正在使用的代码。
上传图片时出现错误
var inputFile = $(" input [type = file]")[0] .files [0]; ^ $未定义
exports.upload = function(req, res){
var CREDENTIALS ={
appId: 0000,
authKey: 'xxxxx',
authSecret: 'yyyyyyyy'
};
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret);
var user ={
id: 1234,
name: 'abcd',
email: 'ab@gmail.com',
pass: 'qwertyuiop'
};
QB.createSession({email: user.email, password: user.pass
}, function(err,res){
console.log(res)
if (res){
var inputFile = $("input[type=file]")[
0
].files[
0
];
var params ={name: inputFile.name, file: inputFile, type: inputFile.type, size: inputFile.size, 'public': false
};
QB.content.createAndUpload(params, function(err, response){
if (err){
console.log(err);
}
else{
console.log(response);
var uploadedFile = response;
var uploadedFileId = response.id;
}
});
}
});
}
答案 0 :(得分:1)
使用document.querySelector(“input [type = file]”)。files [0]而不是$(“input [type = file]”)[0] .files [0]。或者添加JQuery