Skip to content

[Bug] file extension not saved #67

Description

@yo-gen

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

Activity

  1. changed the title [-][Bug] [/-] [+][Bug] file extension not saved[/+] on Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions