簡體   English   中英

將 data.json 文件從 postman 發送到 node.js

[英]send a data.json file to node.js from postman

我想發送一個data.json文件,存儲在我的桌面上到 node.js function。我的data.json文件的結構是:

[{"key":"value"}, {same key value structure for 8000 entries}]

這是一本通訊錄,基本上以字符串格式存儲姓名和聯系電話,所有這些都存儲在一個數組中。 數組中有很多 json 個對象。 現在我想將它發送到我的后端(帶有 express 的 node.js)並將其存儲在一個變量中。

我正在嘗試使用 postman,我將文件放入表單數據並將其發送到我的快遞 api。

app.post('/upload', function (req, response) {
      console.log(data);
      response.send(data);
});

但它以空 object 的形式登錄到控制台,就像{}一樣。

我希望我解釋了我的問題。

在HTML,

<input name="file" type="file" (change)=filechanged($event)/>

在typescript,

filechanged(e) {
  this.file = e.target.files[0];
  let fileReader = new FileReader();
  fileReader.onload = (e) => {
    this.Name = fileReader.result;
    this.data = this.Name;
  };
  fileReader.readAsText(this.file);
}

submit() {
  var formdata = new FormData();
  formdata.append("file", JSON.stringify(this.data));
}

您通過formdata發送此表單數據

在后端,

app.post("/upload", function (req, response) {
  var data = JSON.parse(req.body.file);
  response.send(data);
});

暫無
暫無

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

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