breakroom / multipart Goto Github PK
View Code? Open in Web Editor NEWConstructs a multipart message, such an HTTP form data request or multipart email
License: MIT License
Constructs a multipart message, such an HTTP form data request or multipart email
License: MIT License
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)
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
Under Installation
{:multipart, "~> 0.1.0"}
we're now at 0.4.0
:)
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.
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.
Could you update to v2 for mime?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.