-
Notifications
You must be signed in to change notification settings - Fork 341
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
Making a HTTPoison POST multipart request with more data other than the file #237
Comments
I think the problem here is that |
As you can see there are three versions of the form. The atom one is the third posted (first tried), and it gave me that error ( Then I tried making it a string and got the 1st error (second tried) where it passes the whole form as first argument to Hackney, and then since it doesn't read it in first level, gives it an accSize of 0 as second argument and Hackney just doesn't know what to do with that. What I don't know is how to pass this to Elixir so that it will pass it to Hackney in a proper format (I know no Erlang at all) for it to be processed effectively. And, as far as I know (and as far as I've tried and asked around) this issue may be due to a problem in HTTPoison. |
+1 I'm also having trouble getting this to work. I need to POST an image file as well as a text argument (subscription_key for example), but no matter what I try I can't get HTTPoison to recognize anything past the :file .... |
See this post on Elixir Forum that I made, I explore the topic and get to the point where I think this is an issue with the module. To sum up, the message one sends has to have a field for the file, say content-disposition: |
Have you checked the docs of the Example:
I saw that your keys are nested but AFAIK there's no support for this. What kind of request are you expecting? Can you show using curl for example? |
Same issue here, have you found a way to upload a file along with json data? |
@edgurgel I have the same problem but like you stated the problem could come from hackney This is the CURL I'm trying to translate into httpoison
The file need to be named |
I digged deeper and found the solution :
For this use case you need to use file = "/some/path/video.mp4"
HTTPoison.post(
"https://api.vid.me/video/upload",
{:multipart, [{:file, file, {"form-data", [name: "filedata", filename: Path.basename(file)]}, []}]},
["AccessToken": "XXXXX"]
) |
You should use multipart body like: form = {:multipart, [{"chat_id", "237799110"}, {:file, file_path, {"form-data", [{:name, "photo"}, {:filename, Path.basename(file_path)}]}, []}]}
Check that :) |
@DmitryKK in my case with code
I get
Update: nvm sorry forgot to add the empty list after the file name |
@DmitryKK Passing body params in this way does not show up on our receiving end but end end but our files do. I'm passing files from a new API endpoint for the sake of utilizing an old one to do the heavy lifting for GDrive. This shim for an API upgrade/re-write. You are correct about passing atoms as it will trigger an error. But when passing them as strings its as if they never get picked up. Hmmm... I've tried everything and I'm wondering if this has to do with how Keyword lists and Tuple based lists get processed. |
@DmitryKK Nevermind! Of course it's not a problem w/Hackney! The problem is that NodeJS Express multer lib does not seem to understand the spec that is being send or I require additional config on that end. This would be our v1 API. This just re-enforces that it's good to move off Express. |
@DmitryKK there is an issue w/content-type when you make requests against against express/multer and you have to build the request like is being advised. The request you make is actually being incorrectly stamped with application/octet-stream which it is NOT. It is text/plain. You should probably update your code either way. @edgurgel Here's a full example which should help the greater community gain some insight.
|
I'm trying to build a function to send a file through a POST request in multipart format, using this as guide, but HTTPoison keeps giving me a two errors no matter what changes I make to the form. They are all
HTTPoison.post("https://api.telegram.org/myCredentials", {:multipart, form}, headers)
and the three versions of my form and the errors are the following (whether I use headers or not):
1st and 2nd Version (same error for both):
And the third version:
form = [chat_id: 237799110, photo: [{"name", "myphoto.jpg"}, {:file, "files/aphoto.jpg"}]]
Which gives me the following error:
Is this a problem by HTTPoison? Am I doing something wrong?
The text was updated successfully, but these errors were encountered: