簡體   English   中英

Nodejs Post 請求在 Postman 中不起作用?

[英]Nodejs Post request is not working in Postman?

我做了一篇谷歌雲視覺的帖子 API 用於檢測圖像文本,現在我正在嘗試在 postman 中測試這篇帖子 API ,但它不起作用。 沒有得到任何回應

app.post("/images", upload.single("file"), function (req, res) {
  client.textDetection(req.file.path)
  .then((results) => {
  res.send(results);
 })
 .catch((err) => {
  res.status(400).send(err);
 });
});

postman -

使用 url - http://localhost:8088/images

在此處輸入圖像描述

var http = require('http');
var formidable = require('formidable');
var fs = require('fs');

http.createServer(function (req, res) {
if (req.url == '/fileupload') {
var form = new formidable.IncomingForm();
form.parse(req, function (err, fields, files) {
  var oldpath = files.filetoupload.filepath;
  var newpath = 'C:/Users/Your Name/' + 
files.filetoupload.originalFilename;
  fs.rename(oldpath, newpath, function (err) {
    if (err) throw err;
    res.write('File uploaded and moved!');
    res.end();
  });
});
} else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<form action="fileupload" method="post" enctype="multipart/form- 
data">');
res.write('<input type="file" name="filetoupload"><br>');
res.write('<input type="submit">');
res.write('</form>');
return res.end();
  }
}).listen(8080);

upload.single("file")表示multer將查找名為file的表單部分。

但是,在您的 Postman 屏幕截圖中,名稱(“KEY”)為空。

暫無
暫無

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

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