使用回调作为参数时遇到了麻烦。
这是来源。
authRequiredCall(socket1, 'media_file_add', function(userInfo, message) {
saveMediaFile(message.project_id, message.path, function(err, result) {
console.log('send media_file_add response: ' + JSON.stringify(result))
socket1.emit('media_added', result);
});
});
function saveMediaFile(project_id, file_path, callback) {
download(file_path, './uploads/')
.on('close', function () {
console.log('One file has been downloaded.');
var filename = path.basename(file_path);
putMediaToS3bucketAndSaveToDB(project_id, filename, callack);
});
}
function putMediaToS3bucketAndSaveToDB(project_id, filename, callack) {
...
uploader.on('end', function() {
var uploadedPath = s3.getPublicUrl(config.s3_config.BUCKET_NAME, newFilename, "");
console.log("FILE UPLOADED", uploadedPath);
fs.unlink("uploads/"+filename);
uploadedPath = uploadedPath.replace('s3', 's3-us-west-2');
console.log("PATH", uploadedPath);
//Saving the file in the database
addMediaFile(project_id, uploadedPath, callback);
});
}
function putMediaToS3bucketAndSaveToDB(project_id, filename, callack) {
...
uploader.on('end', function() {
var uploadedPath = s3.getPublicUrl(config.s3_config.BUCKET_NAME, newFilename, "");
console.log("FILE UPLOADED", uploadedPath);
fs.unlink("uploads/"+filename);
uploadedPath = uploadedPath.replace('s3', 's3-us-west-2');
console.log("PATH", uploadedPath);
//Saving the file in the database
addMediaFile(project_id, uploadedPath, callback);
});
}
正如您所看到的,我正在尝试将回调作为参数发送到SaveMediaFile,但是当我使用回调参数调用putMediaToS3buketAndSaveToDB函数时,它会返回错误消息。
ReferenceError:未定义callack
我不知道为什么在project_id和file_path有值的情况下没有定义回调。
有没有人教我原因?
帮助我!!!
答案 0 :(得分:0)
因为你有拼写错误
function putMediaToS3bucketAndSaveToDB(project_id, filename, callack)
^