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

File uploading #144

Closed
dongmaster opened this issue Jun 13, 2016 · 1 comment
Closed

File uploading #144

dongmaster opened this issue Jun 13, 2016 · 1 comment

Comments

@dongmaster
Copy link

dongmaster commented Jun 13, 2016

Not sure what to title this
Trying to upload a file using {:file, "/path/to/file"} to https://p.fuwafuwa.moe does not work.
curl can do it.
Here are the differences between how curl and httpoison does it:

curl

curl --silent -sf -F files\[\]="@test.txt" http:https://httpbin.org/post

{
  "args": {}, 
  "data": "", 
  "files": {
    "files[]": "testlmao\n"
  }, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "198", 
    "Content-Type": "multipart/form-data; boundary=------------------------d7914e35b1cf9114", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.46.0"
  }, 
  "json": null, 
  "origin": "redacted", 
  "url": "http:https://httpbin.org/post"
}

When we try to upload to fuwafuwa.moe:
(JSON response)

{"success":true,"files":[{"hash":"7ddd25022f061412a0ee899eb48928ff697b53d9","name":"test.txt","url":"https:\/\/p.fuwafuwa.moe\/gcctxc.txt","size":9}]}

and

httpoison

HTTPoison.post("http:https://httpbin.org/post", {:file, "test.txt"})

{  
    "args": {}, 
    "data": "testlmao", 
    "files": {}, 
    "form": {},
    "headers": {
        "Content-Length": "9", 
        "Content-Type": "text/plain", 
        "Host": "httpbin.org", 
        "User-Agent": "hackney/1.6.0"
    }, 
    "json": null, 
    "origin": "redacted", 
    "url": "http:https://httpbin.org/post"
}

When we try to upload a file to fuwafuwa.moe:
(JSON response)

{"success":false,"errorcode":400,"description":"No input file(s)"}

Edit: Found the solution.

HTTPoison.post("https://p.fuwafuwa.moe/upload.php", {:multipart, [{:file, "test.txt", {"form-data", [{"name", "files[]"}, {"filename", "testus.txt"}]}, []}]})
@edgurgel
Copy link
Owner

edgurgel commented Sep 1, 2016

Awesome that a solution was found :)

@edgurgel edgurgel closed this as completed Sep 1, 2016
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