我在 Node.js 下的 Javascript 方面遇到了很大的困难,它应该从磁盘读取文件并通过后期请求将其发布到 DeepStack 面部识别系统以对其执行某些操作。
我目前总是收到 400 代码 -->“未找到有效的图像文件”
我认为这可能与文件没有通过 Axios 作为后有效负载传输有关。
我正在使用以下代码:
const fs = require("fs")
const axios = require("axios")
const FormData= require('form-data')
var image_stream = fs.createReadStream('./somefile.jpg')
var form = new FormData()
form.append('image', image_stream);
axios({
method: "post",
url: "http://192.168.178.46:666/v1/vision/face/recognize",
headers: { 'Content-Type': 'multipart/form-data'},
data: form,
timeout: 1000
}).then(function (response) {
// do some stuff with the response
}).catch(function(error){log(error)})
createReadStream
和ReadFileSync
都不起作用,而且我在标题和表单数据上尝试过的所有内容都不起作用。
我也尝试过fetch
和其他包来发送数据,但没有成功。
你能帮我提供建议吗?
多部分请求可能没有很好地形成,所以,尝试:
content-type
标题:axios({
method: "post",
url: "http://192.168.178.46:666/v1/vision/face/recognize",
data: form,
timeout: 1000
axios({
method: "post",
url: "http://192.168.178.46:666/v1/vision/face/recognize",
headers: { ...form.getHeaders() },
data: form,
timeout: 1000