繁体   English   中英

图像未上传到node.js中定义的文件夹

[英]Image is not uploaded to defined folder in node.js

我有一个小的HTML模板,我想要的是将图像从一个位置上传到另一个位置。 选择并单击上传按钮后,响应显示“成功上传”,但是图像不在目标文件夹中。 请查看以下代码。

的HTML

<form id="frmUploader" enctype="multipart/form-data" action="book/api/Upload/" method="post">
    <input type="file" name="imgUploader" multiple />
    <input type="button" name="submit" id="btnSubmit" value="Upload" onclick="upload()"/>
</form>

index.js

function upload() {
    axios.post(baseUrlLocal+'/book/api/Upload', {headers: headers})
    .then(response => {
        console.log(response.data.success)
        if (response.data.success) {
            console.log("hi: "+response)
        // $.notify("New Book is Added to your Library", "success");

    }
        })
        .catch(function (error) {
            console.log(error)
            // $.notify("Please check all the details","warn");
        });
}`

book.js

var Storage = multer.diskStorage({
destination: function(req, file, callback) {
    callback(null, "../public/images/");
},
filename: function(req, file, callback) {
    callback(null, file.fieldname + "_" + Date.now() + "_" + 
file.originalname);
}
 });

var upload = multer({
storage: Storage
 }).array("imgUploader", 3);



router.get("/image", function(req, res) {
res.sendFile(__dirname + "/index.html");
});
`router.post("/api/Upload", function(req, res) {
upload(req, res, function(err) {
    if (err) {
        return res.end("Something went wrong!");
    }
    return res.end("File uploaded sucessfully!.");
});
 });`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM