【发布时间】:2021-06-11 13:16:31
【问题描述】:
所以我有一个包,其中包含将文件上传到 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”一起上传。
我正在尝试将其放入电子应用程序中,因此我在 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 中完全相同?
【问题讨论】:
标签: javascript node.js electron twilio node-modules