From 0719036378f2d3e0ec0a73014398fcba69bd76f8 Mon Sep 17 00:00:00 2001 From: Maarten Claes Date: Tue, 27 Mar 2018 15:07:21 +0200 Subject: [PATCH] Support ActionDispatch::Http::UploadedFile again Using the `path` method instead of passing the file directly to `File.basename` to get the filename ensures that `ActionDispatch::Http::UploadedFile` can be used again. Related issue: https://github.com/jnunemaker/httparty/issues/584 --- Changelog.md | 4 ++++ lib/httparty/request/body.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index e644e850..9c6364d0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +## Unreleased + +* [Support ActionDispatch::Http::UploadedFile again](https://github.com/jnunemaker/httparty/pull/585) + ## 0.16.1 * [Parse content with application/hal+json content type as JSON](https://github.com/jnunemaker/httparty/pull/573) diff --git a/lib/httparty/request/body.rb b/lib/httparty/request/body.rb index 2f045207..bfb15624 100644 --- a/lib/httparty/request/body.rb +++ b/lib/httparty/request/body.rb @@ -32,7 +32,7 @@ def generate_multipart multipart = normalized_params.inject('') do |memo, (key, value)| memo += "--#{boundary}\r\n" memo += %(Content-Disposition: form-data; name="#{key}") - memo += %(; filename="#{File.basename(value)}") if file?(value) + memo += %(; filename="#{File.basename(value.path)}") if file?(value) memo += "\r\n" memo += "Content-Type: application/octet-stream\r\n" if file?(value) memo += "\r\n"