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

Filename mimetype overrides #145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HappyHax0r
Copy link
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).

… hash containing a file handle, filename, and mimetype (filename and mimetype are optional)
@HappyHax0r
Copy link
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.

2 participants