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

multipart upload #47

Closed
jschoch opened this Issue Mar 31, 2015 · 8 comments

Comments

Projects
None yet
2 participants
@jschoch

jschoch commented Mar 31, 2015

any plans to support multipart upload? Is this possilbe today, or do you need to use hackney_multipart somehow?

@edgurgel

This comment has been minimized.

Owner

edgurgel commented Apr 1, 2015

You should be able to do something like:

iex> IO.puts HTTPoison.post!("httpbin.org/post", {:multipart, [{"name", "value"}, {:file, "/etc/hosts"}]}).body
{
  "args": {},
  "data": "",
  "files": {
    "file": "##\n# Host Database\n#\n# localhost is used to configure the loopback interface\n# when the system is booting.  Do not change this entry.\n##\n127.0.0.1\tlocalhost\n255.255.255.255\tbroadcasthost\n::1             localhost \nfe80::1%lo0\tlocalhost\n"
  },
  "form": {
    "name": "value"
  },
  "headers": {
    "Content-Length": "616",
    "Content-Type": "multipart/form-data; boundary=---------------------------hitckzclxlucgpym",
    "Host": "httpbin.org",
    "User-Agent": "hackney/1.0.6"
  },
  "json": null,
  "origin": "210.54.34.29",
  "url": "http://httpbin.org/post"
}

HTTPoison will support exactly what hackney accepts as possible request body: https://github.com/benoitc/hackney#send-a-body

@jschoch

This comment has been minimized.

jschoch commented Apr 1, 2015

Thanks a ton!

are you aware of a way to change the Content-Disposition name from "file" to "content", do I need to set Disposition in extraheaders or something?

@jschoch

This comment has been minimized.

jschoch commented Apr 1, 2015

btw, i've tried this, but the extraheaders don't override

options = {:multipart,[
  {:file, filename,[{"filename",filename},{"Content-Type","image/jpeg"},{"name","content"}]}
]}

this creates the following

Content-Type: multipart/form-data; boundary=---------------------------mtynipxrmpegseog
User-Agent: hackney/1.0.6
Host: localhost:9010
Content-Length: 291

-----------------------------mtynipxrmpegseog
content-length: 48
content-disposition: form-data; name=file; filename="test.txt"
filename: test.txt
content-type: image/jpeg
name: content

I need name=file to be name=content, but i'm not sure how to get that form element set correctly in conjunction with :file

@jschoch

This comment has been minimized.

jschoch commented Apr 1, 2015

ok, i've been able to get the request the way I want it via hackney directly, but the amazon cloud drive api isn't liking the request

    url = "http://localhost:9010/foo"
    filename = "test.txt"
    header = ["Authorization": "Bearer #{@at}"]
    options = {:multipart, [
        {:file, filename, {"form-data",
          [{"name", "content"}, {"filename", filename}]},
          [{"Content-Type", "image/jpeg"}]
        },
        {"metadata", ~s({"name":#{filename},"kind":"FILE"})}
      ]}
    res = :hackney.post(url, header, options)
@edgurgel

This comment has been minimized.

Owner

edgurgel commented Apr 2, 2015

I wonder if you are hitting this issue: benoitc/hackney#171

@jschoch

This comment has been minimized.

jschoch commented Apr 2, 2015

This was an issue with the api endpoint I was using. closing the issue.

@jschoch jschoch closed this Apr 2, 2015

@edgurgel

This comment has been minimized.

Owner

edgurgel commented Apr 2, 2015

Oh! Great! I will probably add a test to have an "example" there for multipart upload.

@edgurgel

This comment has been minimized.

Owner

edgurgel commented Sep 1, 2016

Done by af3931f

@edgurgel edgurgel reopened this Sep 1, 2016

@edgurgel edgurgel closed this Sep 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment