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

httparty not uploading files #691

Open
timuckun opened this issue Mar 19, 2020 · 1 comment
Open

httparty not uploading files #691

timuckun opened this issue Mar 19, 2020 · 1 comment

Comments

@timuckun
Copy link

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

@TheSmartnik
Copy link
Collaborator

@timuckun Hi! What's your httparty version?

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

No branches or pull requests

2 participants