1
我可以使用Node.Js和Multer上傳圖像。圖像以加密格式保存爲隨機名稱。如何在.jade文件或.hetml文件中檢索和顯示圖像?Node Js Retrive和顯示圖像
//My Code to upload image
router.post("/upload", function(req, res, next){
if (req.files) {
console.log(util.inspect(req.files));
if (req.files.myFile.size === 0) {
return next(new Error("Hey, first would you select a file?"));
}
fs.exists(req.files.myFile.path, function(exists) {
if(exists) {
res.end("Got your file!");
} else {
res.end("Well, there is no magic for those who don’t believe in it!");
}
});
}
});
// Upload page (Jade file)
form#fileUpload(method="post" action="/uploads/upload" enctype="multipart/form-data")
label(for="payload") Select a file to upload:
input#fileToUpload(type='file', name='myFile')
//input#payload(type="file" name="myFile" accept="image/*")
br
button#upload Upload
Any help?
謝謝Ashok .. – Suhaila