New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot upload binary using files.upload
facet
#103
Comments
Thanks, will check this out today |
…ck API correctly, by switching to formData mode with the request module when a file is supplied in the args to an API method. Fixes #103
Sorry for the delay on this, I got busy and then was on vacation for a week. I believe the above PR fixes this. |
…ck API correctly, by switching to formData mode with the request module when a file is supplied in the args to an API method. Fixes #103
It's not working still. I tried to send a picture in chat but Slack sees it as a text and it shows as text. let WebClient = require("@slack/client").WebClient;
let web = new WebClient(accessToken);
let opts = {
content: fs.readFileSync(imageFilePath),
filename: 'image.jpg',
title: 'image.jpg',
channels: 'demo'
};
web.files.upload(msg.photo.caption, opts, (err, res) => {
if (err) {
// no errors here
} else {
// here i receive the data about the uploaded file, and there it is listed as plain text
}
}); Of course, I found the solution on the advice of @pveyes. |
@webus shouldn't you use |
@l12s // doesn't work (see trace log below)
const image = fs.readFileSync('image.png');
await bot.files.upload('image.png', {
file: image
});
// text buffer doesn't work too
await bot.files.upload('text.txt', {
file: new Buffer('hello world');
});
// uploads image as Plain Text (incorrect)
await bot.files.upload('image.png', {
content: image
});
// works well with streams
const imageStream = fs.createReadStream('image.png')
await bot.files.upload('image.png', {
file: imageStream
}); 2016-12-27T13:58:29.415Z - error: Error: no_file_data
at handleHttpResponse (/bot/node_modules/@slack/client/lib/clients/transports/call-transport.js:105:17)
at handleTransportResponse (/bot/node_modules/@slack/client/lib/clients/transports/call-transport.js:155:19)
at apply (/bot/node_modules/lodash/lodash.js:499:17)
at wrapper (/bot/node_modules/lodash/lodash.js:5356:16)
at Request.handleRequestTranportRes (/bot/node_modules/@slack/client/lib/clients/transports/request.js:20:5)
at apply (/bot/node_modules/lodash/lodash.js:499:17)
at Request.wrapper [as _callback] (/bot/node_modules/lodash/lodash.js:5356:16)
at Request.self.callback (/bot/node_modules/request/request.js:186:22)
... |
I can also verify that |
See my answer to #307 for uploading a buffer via the |
Version: 2.0.0-beta2
Cannot send binary file to upload via
files.upload
. I tried using Buffer and ReadStream (viafs.createReadStream
) but no luck.Here's my code (more or less)
If I call api directly using
request
module, I can sent them (usingr.form()
)The text was updated successfully, but these errors were encountered: