Skip to content
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

Set a default filename so that Slack displays the preview correctly #375

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ts-3156
Copy link

@ts-3156 ts-3156 commented May 7, 2021

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
スクリーンショット 2021-05-07 21 52 06 スクリーンショット 2021-05-07 21 47 43

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.

@dangerpr-bot
Copy link

2 Warnings
⚠️ There're library changes, but not tests. That's OK as long as you're refactoring existing code.
⚠️ 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 🚫 Danger

@dblock
Copy link
Collaborator

dblock commented May 10, 2021

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!

@dblock dblock force-pushed the master branch 4 times, most recently from 1963b52 to 097b3ca Compare April 30, 2023 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants