slack-ruby-client
slack-ruby-client copied to clipboard
Set a default filename so that Slack displays the preview correctly
Starting at 2021/05/05 05:30 UTC, Slack client no longer correctly displays previews of images when filename is not specified via slack-ruby-client gem.
Expectation | Reality |
---|---|
![]() |
![]() |
The reason of this behavior is that when a filename is not set to both Faraday::UploadIO.new
and Slack::Web::Client.new.files_upload
, multipart-post gem sets local.path
as a filename. If local.path
is specified as the filename, Slack will recognize the file as binary and will not show the image preview. In this pull request, I specify the default filename to avoid this behavior.
# An example of files.upload API
image = File.binread('image.png')
file = Faraday::UploadIO.new(StringIO.new(image), '_content_type_', 'can_specify_filename_here')
Slack::Web::Client.new.files_upload(channels: '#general', file: file, filename: 'can_specify_filename_here_too')
# The location where local.path is specified
# https://github.com/socketry/multipart-post/blob/master/lib/multipart/post/composite_read_io.rb#L83
local_path = filename_or_io.respond_to?(:path) ? filename_or_io.path : "local.path"
The solution of specifying a default filename may be out of scope for slack-ruby-client gem. If you think so, please feel free to close this pull request.
2 Warnings | |
---|---|
:warning: | There're library changes, but not tests. That's OK as long as you're refactoring existing code. |
:warning: | Unless you're refactoring existing code or improving documentation, please update CHANGELOG.md. |
Here's an example of a CHANGELOG.md entry:
* [#375](https://github.com/slack-ruby/slack-ruby-client/pull/375): Set a default filename so that slack displays the preview correctly - [@ts-3156](https://github.com/ts-3156).
Generated by :no_entry_sign: Danger
This file is generated, so you'll need to introduce this as a patch, or we'll lose the change next update of the web API, see https://github.com/slack-ruby/slack-ruby-client/blob/master/CONTRIBUTING.md#patching-slack-web-api. It will also need tests and a README change. Thanks!