ฉันกำลังพยายามอัปโหลดรูปภาพผ่าน Slack โดยใช้ node.js และ แพ็คเกจคำขอ แต่ไม่มี โชคดีมาก ฉันได้รับข้อผิดพลาด invalid_array_arg
หรือ no_file_data
จาก API
นี่คือคำขอของฉัน:
var options = { method: 'POST',
url: 'https://slack.com/api/files.upload',
headers:
{ 'cache-control': 'no-cache',
'content-type': 'application/x-www-form-urlencoded' },
form:
{ token: SLACK_TOKEN,
channels: SLACK_CHANNEL,
file: fs.createReadStream(filepath)
} };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
ฉันได้ดูโพสต์ที่เกี่ยวข้องบางส่วน:
- ฉันสามารถอัปโหลดรูปภาพเป็นไฟล์แนบด้วย Slack API ได้หรือไม่< /ก>
- Slack API (files.upload) โดยใช้ NodeJS
- แก้ไข files.upload จาก Buffer ด้วยตัวเลือก formData #307
สิ่งเดียวที่ได้ผลคือการใช้คำสั่ง curl โดยตรง แต่การใช้ cygwin (CommandPrompt ล้มเหลว: curl: (1) Protocol https not supported or disabled in libcurl
) ปัญหาในการเรียก curl จากโหนด (โดยใช้ child_process
) แต่ล้มเหลวอย่างเงียบ ๆ ใน Command Prompt และยังคงส่งคืน no_file_data
โดยใช้ cygwin (ส่งผ่านเส้นทางที่แน่นอนไปยังไฟล์):
stdout: {"ok":false,"error":"no_file_data"}
stderr: % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 469 100 35 100 434 359 4461 --:--:-- --:--:-- --:--:-- 6112
ฉันใช้โหนด v6.9.1 บน Windows
ฉันพลาดอะไรไป? ฉันจะอัพโหลดรูปภาพเพื่อหย่อนผ่าน node.js บน Windows ได้อย่างไร
error: Response not OK: no_file_data Error: no_file_data
อย่างน่าประหลาดใจ - person George Profenza   schedule 07.02.2018fs.createReadStream(filepath).stat()
พูดว่าอะไร? - person Peter   schedule 07.02.2018console.log(fs.createReadStream(filename).stat()); ^ TypeError: fs.createReadStream(...).stat is not a function
- person George Profenza   schedule 07.02.2018gm
's'close'
ในกรณีของคุณ อาจมี Listener ให้ใช้เมื่อไฟล์ pdf เขียนลงดิสก์เสร็จแล้ว เพื่อเป็นการพิสูจน์แนวคิด คุณสามารถลองแฮ็กsetTimeout
ถึง 10 วินาทีหรืออะไรสักอย่าง (หาก PDF ไม่ใหญ่มาก) เพื่อแยกปัญหาและยืนยันว่าเป็นปัญหาเดียวกัน หากเป็นกรณีนี้ ตามหลักการแล้ว คุณจะต้องลบความล่าช้าในการแฮ็กออก และใช้เหตุการณ์ที่ถูกต้อง ขออภัยที่กลับล่าช้า - person George Profenza   schedule 19.09.2019