I'm trying to upload a file to slack but constantly getting an error saying invalid_form_data
.
(我正在尝试将文件上传到Slack,但不断收到一条错误消息,说invalid_form_data
。)
I'm building an electronJS app and using the following code to upload the file:(我正在构建一个electronicJS应用程序,并使用以下代码上传文件:)
const filee = fs.createReadStream(file);
(async () => {
const result = await web.files.upload({
channels: '#general',
file: filee
})
})()
I have even tried to post using axios but ran into the same problem.
(我什至尝试过使用axios发布,??但遇到了同样的问题。)
The code is:(代码是:)
const upload_url = 'https://slack.com/api/files.upload'
let file = null
fs.readFile(file_path, 'utf-8', function (err, data) {
file = data
});
const post = {
channels: "#general",
file: file
}
axios.post(upload_url, post, {
headers: {
'Content-Type': 'multipart/form-data',
"Authorization": `Bearer ${token}`
}
}).then(function (response) {
console.log(response['data']['ok'])
}).then(function (err) {
console.log(err)
})
I have also tried formData module, like so:
(我也尝试过formData模块,如下所示:)
const upload_url = 'https://slack.com/api/files.upload'
const formData = new FormData();
let file = null
fs.readFile(file_path, function (err, data) {
file = data
});
formData.append("file", file);
axios.post(upload_url, formData, {
headers: {
'Content-Type': 'multipart/form-data',
"Authorization": `Bearer ${token}`
}
}).then(function (response) {
console.log(response['data']['error'])
}).then(function (err) {
console.log(err)
})
What am I doing wrong?
(我究竟做错了什么?)
ask by rootkit translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…