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

[Bug] file extension not saved #67

Open
yo-gen opened this issue Oct 17, 2021 · 0 comments
Open

[Bug] file extension not saved #67

yo-gen opened this issue Oct 17, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@yo-gen
Copy link

yo-gen commented Oct 17, 2021

Bug report:

  • Expected Behavior:
    If you are willing to add a specific filename to your attachment, or send in a specific content type for your file, you can use data: to attach the base64 data and specify your filename:, content_type: and/or identify: hash keys
  • Actual Behavior:
    Identify Hash key doesn't identify the file extension automatically. Infact the extension is not recognized when uploading a valid base 64 URI.
  • Steps to Reproduce:
    1. Create a model with a field for attachment
    2. Pass a base64 data URI to file attachment and save it. Pass only the base 64 string in data, without filename and content_type parameters.
    3. Check the filename and it does not have an extension. Filename will have the random generated time string but will lose the extension.
  • Create an executable test case: use the bug_report_template.rb as a starting point.
    You can execute it by running ruby the_bug_report_filename.rb
  • Version of the repo:
  • Ruby and Rails Version:
  • Rails Stacktrace: this can be found in the log/development.log or log/test.log, if this is applicable.

I think a way for this might be to identify the extension from the file content_type using:

require 'rack/mime'
extension = Rack::Mime::MIME_TYPES.invert[attachment[:content_type]]
filename += extension
@yo-gen yo-gen added the bug Something isn't working label Oct 17, 2021
@yo-gen yo-gen changed the title [Bug] [Bug] file extension not saved Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant