Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG][Ruby] Unable to detect content type in form-data file upload using Faraday #17851

Closed
5 of 6 tasks
dvacca-onfido opened this issue Feb 13, 2024 · 0 comments
Closed
5 of 6 tasks

Comments

@dvacca-onfido
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Using faraday as network library, generated ruby client is not able to detect the mime file type when performing file upload as part of a multipart/form-data payload, but it's just using application/octet-stream. That's hardcoded and it's not even possible to change that via some parameter. Looking at the generated code, there is a TODO we'd like to fix:

           when ::File, ::Tempfile
            # TODO hardcode to application/octet-stream, need better way to detect content type
            data[key] = Faraday::FilePart.new(value.path, 'application/octet-stream', value.path)
openapi-generator version

Issue found in version 7.2.0+ (haven't checked previous versions).

OpenAPI declaration file content or url

https://github.com/onfido/onfido-openapi-spec/blob/2f6f506977ecbb340b80c6d31a2dffcb3cedf2bb/generated/artifacts/openapi-yaml/openapi/openapi.yaml#L199-L222

Generation Details
inputSpec: /local/openapi.yaml
useOneOfDiscriminatorLookup: true
invokerPackage: Onfido
packageName: onfido-ruby
moduleName: Onfido
library: faraday
Steps to reproduce
require "onfido"

Onfido.configure do |config|
  config.api_key['Token'] = "Token token=#{ENV["API_KEY"]}"
  config.debugging = true
end

document = onfido_api.upload_document('passport', 'random-uuid', File.open('example.jpg'))

Logs:

{"type"=>"passport", "applicant_id"=>"random-uuid", "file"=>#<Multipart::Post::UploadIO:0x000000011e326508 @content_type="application/octet-stream", @original_filename="example.jpg", @local_path="example.jpg", @io=#<File:example.jpg>, @opts={}>}

For a jpg image, we'd have expected to have received image/jpeg in place of application/octet-stream.

Related issues/PRs

N/A

Suggest a fix

Use ruby-filemagic gem to detect the content type (PR coming soon).

wing328 pushed a commit that referenced this issue Feb 14, 2024
…#17851) (#17853)

* fix(ruby): Detect content-type in form-data file upload using faraday (#17851)

* Update samples

* Add needed dependency libmagic-dev into node 1 setup of Circle Parallel CI

* After merge/pull last master + regeneration of samples
@wing328 wing328 closed this as completed Feb 15, 2024
kota65535 pushed a commit to kota65535/openapi-generator that referenced this issue Feb 23, 2024
…OpenAPITools#17851) (OpenAPITools#17853)

* fix(ruby): Detect content-type in form-data file upload using faraday (OpenAPITools#17851)

* Update samples

* Add needed dependency libmagic-dev into node 1 setup of Circle Parallel CI

* After merge/pull last master + regeneration of samples
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants