Giter Site home page Giter Site logo

multipart's Issues

Question. How do I add a multipart section for file content that's already in memory?

I've created an OpenAI API client for elixir. Currently I'm using Tesla because it already supports multi-part file uploads. I'd like to switch to using Finch with multipart.

I'm looking for the equivalent of Tesla.Multipart.add_file_content, but there doesn't seem to be one.

I'd be happy to create a PR that would provide it if you're interested.

UPDATE. I have created PR #15 which I am already using in my library.

Multipart decoding

Hey @tomtaylor, great work!

Do you think/would consider a PR adding support for multipart decoding? I can't seem to find any elixir implementations suitable for use with an HTTP client to decode multipart responses and I'm stuck with hackney ATM.

Update README

Under Installation

    {:multipart, "~> 0.1.0"}

we're now at 0.4.0 :)

multipart/mixed - ** (ArgumentError) argument error :erlang.iolist_to_iovec

I tried the example in the Readme and I got this error:

  multipart =
  Multipart.new()
  |> Multipart.add_part(Multipart.Part.binary_body("first body"))
  |> Multipart.add_part(Multipart.Part.binary_body("second body", [{"content-type", "text/plain"}]))
  |> Multipart.add_part(Multipart.Part.binary_body("<p>third body</p>", [{"content-type", "text/html"}]))

  body_stream = Multipart.body_stream(multipart) |> IO.inspect
  content_length = Multipart.content_length(multipart)
  content_type = Multipart.content_type(multipart, "multipart/mixed; boundary=mimeboundary")

  token = Base.encode64("username:password")
  headers = [{"Content-Type", "multipart/mixed; boundary=mimeboundary"}, {"Content-Length", "#{content_length}"}, {"Authorization", "Basic #{token}"}]

  Finch.build("POST", url, headers,  body_stream)  |> Finch.request(MyFinch)
** (ArgumentError) argument error
    :erlang.iolist_to_iovec([["POST", 32, "/mms/v2/send", " HTTP/1.1\r\n"], [[[[["", "host", ": ", "mms.example.com", "\r\n"], "user-agent", ": ", "mint/1.2.1", "\r\n"], "content-type", ": ", "multipart/mixed; boundary=mimeboundary", "\r\n"], "content-length", ": ", "42", "\r\n"], "authorization", ": ", "Basic ZGRkZERkZWV3OnNvbWVwYXNz=", "\r\n"], "\r\n", #Function<62.38660007/2 in Stream.transform/3>])
    (ssl 9.6.1) ssl.erl:834: :ssl.send/2
    (mint 1.2.1) lib/mint/core/transport/ssl.ex:368: Mint.Core.Transport.SSL.send/2
    (mint 1.2.1) lib/mint/http1.ex:248: Mint.HTTP1.request/5
    (finch 0.4.0) lib/finch/http1/conn.ex:96: Finch.Conn.request/5
    (finch 0.4.0) lib/finch/http1/pool.ex:43: anonymous fn/8 in Finch.HTTP1.Pool.request/5
    (nimble_pool 0.2.4) lib/nimble_pool.ex:266: NimblePool.checkout!/4
    (finch 0.4.0) lib/finch/http1/pool.ex:36: Finch.HTTP1.Pool.request/5
    (finch 0.4.0) lib/finch.ex:207: Finch.request/3

`{:bad_generator, 252}` when running README example

Love the idea of this project since creating complex multipart in HTTPoison has proven to be such a pain.

But tried the homepage example and got:

** (ErlangError) Erlang error: {:bad_generator, 252}
    (mint 1.3.0) lib/mint/http1/request.ex:84: Mint.HTTP1.Request."-validate_header_value!/2-lc$^0/1-0-"/3
    (mint 1.3.0) lib/mint/http1/request.ex:84: Mint.HTTP1.Request.validate_header_value!/2
    (mint 1.3.0) lib/mint/http1/request.ex:27: anonymous fn/2 in Mint.HTTP1.Request.encode_headers/1
    (elixir 1.13.0) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
    (mint 1.3.0) lib/mint/http1/request.ex:9: Mint.HTTP1.Request.encode/4
    (mint 1.3.0) lib/mint/http1.ex:242: Mint.HTTP1.request/5
    (finch 0.10.2) lib/finch/http1/conn.ex:114: Finch.Conn.request/6
    (finch 0.10.2) lib/finch/http1/pool.ex:46: anonymous fn/8 in Finch.HTTP1.Pool.request/5
    (nimble_pool 0.2.4) lib/nimble_pool.ex:266: NimblePool.checkout!/4
    (finch 0.10.2) lib/finch/http1/pool.ex:39: Finch.HTTP1.Pool.request/5
    (finch 0.10.2) lib/finch.ex:275: Finch.request/3

This is with Finch 0.10.2 and my details:

MacBook-Pro:multipart michael$ elixir --version
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [dtrace]

Elixir 1.13.0 (compiled with Erlang/OTP 24)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.