![](/img/trans.png)
[英]ENOENT: no such file or directory, open 'C:\Users\subwo\package.json'
[英][Error: ENOENT: no such file or directory, open 'C:\Users\Lenovo\Desktop\myCart\public\product_images\.......]
我運行了以下代碼並希望圖像的內容轉到路徑變量中提到的位置,但它卻顯示此錯誤:
[Error: ENOENT: no such file or directory, open 'C:\Users\Lenovo\Desktop\myCart\public\product_images\5e5dfcdb791fbf15a832b374\image.png'] {
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\\Users\\Lenovo\\Desktop\\myCart\\public\\product_images\\5e5dfcdb791fbf15a832b374\\image.png'
}
這是我的代碼:
First Code:
var fileUpload=require('express-fileupload');
Middleware:
app.use(fileUpload());
Add_Products:
<input type="file" accept="image/*" onchange=" previewFile()" name="image" class="form-control">
Post Request:
if(!req.files){
var imageFile=''
}
if(req.files){
imageFile= req.files.image.name;
}
if(imageFile!=''){
var product_image=req.files.image;
var path='public/product_images/'+product._id+'/'+imageFile;
product_image.mv(path,function(err){
if(err){
console.log(err);
}
})
我不確定這是否有效:
product_image.mv(路徑,功能(錯誤){
但另一個問題是,您沒有使用 id 創建目錄。 嘗試將 privture 保存在 public 文件夾中,而沒有帶有 id 的文件夾。
試試這個選項:
Middleware:
app.use(fileUpload({ createParentPath: true }));
默認情況下它是false
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.