Skip to content

Filename mimetype overrides#145

Open
HappyHax0r wants to merge 2 commits intotyphoeus:masterfrom
HappyHax0r:filename_mimetype_overrides
Open

Filename mimetype overrides#145
HappyHax0r wants to merge 2 commits intotyphoeus:masterfrom
HappyHax0r:filename_mimetype_overrides

Conversation

@HappyHax0r
Copy link
Copy Markdown
Contributor

I finally got around to doing this change... This allows you to do something akin to this:

    req = Typhoeus::Request.new('http://localhost:8081/',
                            method: :post,
                            body: { 
                                test: 'test', 
                                test2: 'test2',
                                file: { handle: File.open('somefileondisk.bin', 'r'), filename: 'test.png' }
                            },
                            headers: { 'X-Test' => 'None' },
                            params: 'foo=bar',
                            followlocation: :redirects,
                            multipart: true);

req.run

And will still upload the multipart file, but override the filename (and optionally the mimetype using the mimetype: parameter in the hash) from what would normally be pulled from file_info.

This is useful for anyone using the library who might need to control the filename and mimetype of the file being uploaded (we use it for security tests).

byork added 2 commits February 28, 2018 10:55
… hash containing a file handle, filename, and mimetype (filename and mimetype are optional)
@HappyHax0r
Copy link
Copy Markdown
Contributor Author

(For the record the old way of using just a filehandle hasn't changed... it's still supported. This hash-in-hash technique was the easiest and least-surgery way to provide filename and mimetype overrides)

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.

1 participant