大佬教程收集整理的这篇文章主要介绍了node.js – 在Sails.js后端项目中访问上传的图像,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
avatarUpload: function(req,res) { req.file('avatar').upload({ // don't allow the @R_545_10586@l upload size to exceed ~10MB maxBytes: 10000000,dirname: '../../assets/images' },function whenDone(err,uploadedFiles) { console.log(uploadedFiles); if (err) { return res.negotiate(err); } // If no files were uploaded,respond with an error. if (uploadedFiles.length === 0) { return res.badrequest('No file was uploaded'); } // Save the "fd" and the url where the avatar for a user can be accessed User .update(req.userId,{ // Generate a unique URL where the avatar can be downloaded. avatarUrl: require('util').format('%s/user/avatar/%s',sails.getBaseUrl(),req.userId),// Grab the first file and use it's `fd` (file descriptor) avatarFd: uploadedFiles[0].fd }) .exec(function (err){ if (err) return res.negotiate(err); return res.ok(); }); }); }
我在assets / images文件夹中看到了这个图像 – 就像这样 – 54cd1fc5-89e8-477d-84e4-dd5fd048abc0.jpg
http://localhost:1337/assets/images/54cd1fc5-89e8-477d-84e4-dd5fd048abc0.jpg – 给出404
http://localhost:1337/images/54cd1fc5-89e8-477d-84e4-dd5fd048abc0.jpg – 给出404
以上是大佬教程为你收集整理的node.js – 在Sails.js后端项目中访问上传的图像全部内容,希望文章能够帮你解决node.js – 在Sails.js后端项目中访问上传的图像所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。