簡體   English   中英

如何在nodejs中使用multer更改選擇菜單選項時上傳文件?

[英]How to upload files on changing the select menu options using multer in nodejs?

我想在更改選擇菜單選項欄時上傳文件。 首先,我通過從“選擇文件”選項中選擇文件來上傳文件。 然后單擊選擇菜單,我從狀態列中選擇“完成”選項。

選擇此選項時,我希望此操作意味着我希望使用 POST AJAX 或任何其他方式(如果可能)將所有文件上傳到數據庫。 我怎樣才能做到這一點? 以下是選擇菜單選項和上傳選項的 UI 代碼:

在此處輸入圖片說明

把手側代碼:我正在嘗試以下代碼:

 <td>
      <div class="center">
    <select name="sources" id="{{this.commonID}}" class="custom-select sources" placeholder="{{this.status}}">
      <option value="0" selected="selected">In Progress</option>
      <option value="1" enctype="multipart/form-data" method="post">Done</option>
      <option value="2">Rejected</option>
    </select>
  </div>
  </td>
    <td><span id="deadline"> {{this.deadline}}</span></td>
    <td>
      <input type="file" id="{{this.commonID}}" class="btn btn-outline-warning" name="FileUploadForClient" multiple />
    </td>

在 index.js 這是我的 multer 代碼:

var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, './public/files')
  },
  filename: function (req, file, cb) {
    x = file.originalname; //+path.extname(file.originalname);
  cb(null,x);
  }
});

var upload = multer({storage: storage});

你應該像這樣定義一個 post 請求;

app.post('/uploadImages', upload.array('imageArray', 5), (req, res, next) => {
    const files = req.files;
    if (!files) {
        throw err;
        }

        res.send(files);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM