Sails.js 在sailsjs中上传文件
我是sails js的新手。在我的代码中,我从前端获取了文件,但该文件显示了如下错误。即使我上传的文件也没有保存在后端文件夹中。一旦检查我的代码Sails.js 在sailsjs中上传文件,sails.js,waterline,Sails.js,Waterline,我是sails js的新手。在我的代码中,我从前端获取了文件,但该文件显示了如下错误。即使我上传的文件也没有保存在后端文件夹中。一旦检查我的代码 upload: function(req, res) { if (req.method === 'GET') return res.json({ 'status': 'GET not allowed' }); console.log("Get function is Excuted"); var uploadF
upload: function(req, res) {
if (req.method === 'GET')
return res.json({ 'status': 'GET not allowed' });
console.log("Get function is Excuted");
var uploadFile = req.file('uploadFile');
console.log(uploadFile);
uploadFile.upload({ dirname: './assets/images' },function onUploadComplete(err, files) {
if (err) {
console.log(" Upload file is error");
return res.serverError(err);
}
// IF ERROR Return and send 500 error with error
console.log(files);
res.json({ status: 200, file: files });
});
},
错误代码:
HTML代码:
在我的代码中,我遇到了一个小问题,请检查一下。最好在sails js中给出任何上传文件示例。我最好的猜测是您在上传表单中没有使用正确的编码类型。这里有更多关于这方面的信息 下面是一个简单表单的示例
<form action="/file/upload" enctype="multipart/form-data" method="post">
<input type="file" name="file">
</form>
我最好的猜测是你在上传表单中没有使用正确的编码类型。这里有更多关于这方面的信息 下面是一个简单表单的示例
<form action="/file/upload" enctype="multipart/form-data" method="post">
<input type="file" name="file">
</form>
你看到这个链接了吗?你也可以在前端DropZonesJS中使用。你看到这个链接了吗?你也可以在前端DropZonesJS中使用,我尝试了你建议的方法。但有什么不对劲吗?你能检查并回答这个问题吗?我尝试了你建议的同样的事情。但有什么不对劲吗?你能检查并回答这个问题吗?