httparty
httparty copied to clipboard
httparty not uploading files
trafficstars
I am trying to upload some files along with other data to a PHP form. This is not a proper api, just a form post.
I have written code to post using both curl and httparty, the curl code works but the httparty code doesn't. All the data goes to the server but the server interprets the file data as strings and not file data. Here is the relevant snippet
# In order to test curl vs httparty using the exact same form. Curl requires an @ in front of the file name here we strip it out
filename =form_data[:listingImageFile].gsub('@', '')
puts filename
#File definitely exists
puts File.exist?(filename)
form_data[:listingImageFile] = File.open(filename)
form_data[:otherFile]=File.open(otherfile)
#COOKIE has the authentication in it
cookie_hash = HTTParty::CookieHash.new
cookie_hash.add_cookies(COOKIE)
response = HTTParty.post(
URL,
headers: {'Cookie' => cookie_hash.to_cookie_string},
multipart: true,
follow_redirects: false,
:debug_output => $stdout,
body: form_data
)
File.write("./test_results_party.html", response.body)
puts response.code, response.message, response.headers.inspect
This code runs, it posts all the other form data but the files get interpreted as plain old strings
@timuckun Hi! What's your httparty version?