gpt4 book ai didi

javascript - Axios POST可在Node.js中工作,但不能在Electron中工作

转载 作者:行者123 更新时间:2023-12-03 12:36:51 25 4
gpt4 key购买 nike

所以我有一个带有将文件上传到Twilio的功能的软件包:

const FD = require('form-data');
const axios = require('axios');

async function createFunctionResource(serviceUid, functionUid, client){

let collect_file = "Hello World"

let url = `https://serverless-upload.twilio.com/v1/Services/${serviceUid}/Functions/${functionUid}/Versions`

let form = new FD();
collect_file = "test"

form.append("Path", "collect");
form.append("Visibility", "public");
form.append("Content", collect_file, "collect.js");
form.append("contentType", "application/javascript");

await axios.post(url, form, {
headers: {
Authorization: 'Basic ' + Buffer.from(`${client.accountSid}:${client.password}`).toString('base64'),
...form.getHeaders(),
},
})

}
这在node.js中完全可以正常工作,并且在文件中与消息“Hello World”一起上传。
我试图将其放入 Electron 应用程序中,因此我将这个包预加载到preload.js中,并将nodeIntegration设置为true,但是每当我尝试上传文件时,我都会得到:
Request failed with status code 400
错误响应为:
{"message":"No file attached to request","code":70002,"user_error":true,"http_status_code":400,"params":{}}
预加载软件包是否使其行为与在node.js中完全相同?

最佳答案

您可以在标题部分添加content-type并检查。
“content-type”:“application/json”

关于javascript - Axios POST可在Node.js中工作,但不能在Electron中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66618232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com