์๋๋ ๋ด๊ฐ ์ ๋ก๋ํด์ผ ํ ๊ฒ์ ๋๋ค
-data-binary $'
------WebKitFormBoundaryInmulX6ait6ZMLdu\r\n
Content-Disposition: form-data; name="message"; filename="blob"\r\n
Content-Type: application/json
{
"title":"title of the message to be sent",
"body":"body of the message to be sent",
"attachedFileName":null,
"attachedFileName2":null,
"attachedFileName3":null,
"recipientIdList":[186554]
}
------WebKitFormBoundaryInmulX6ait6ZMLdu--\r\n' --compressed
์๋ฒ๊ฐ ๋ฐ๋ ์ฝํ
์ธ ์ ํ์ multipart/form-data
์
๋๋ค.
๋ด ํ์ฌ ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
client = Faraday::Connection.new(url: BASE_URL) do |builder|
builder.use :cookie_jar
builder.use :multipart
builder.use :url_encoded
builder.adapter :net_http
end
message = {title: "title", body: "body of message", recipientIdList:[186554]}
payload = {message: JSON.dump(message)}
response = @client.post(URL) do |request|
request.headers['Content-Type'] = 'multipart/form-data'
request.body = payload
end
๊ทธ๋ฌ๋ ์๋ฒ์์ ๋ฐ์ ์๋ต์ {"success"=>false, "errorCode"=>nil, "message"=>"Content type 'application/octet-stream' not supported", "data"=>nil}
์
๋๋ค.
์ฝ๋๋ฅผ ์กฐ๊ธ์ฉ ์์ ํ๊ณ ๋ค์ ์๋ํ๊ณ ๋ช ์๊ฐ ๋์ Google์ ๊ฒ์ํ์ง๋ง ์๋ฃจ์
์ ์ฐพ์ ์ ์์์ต๋๋ค.
๋๊ตฐ๊ฐ๊ฐ ๋๋ฅผ ๋์ธ ์ ์๋ค๋ฉด ๋๋จํ ๊ฐ์ฌํ๊ฒ ์ต๋๋ค.
๋ฏธ๋ฆฌ ๊ฐ์ฌ๋๋ฆฝ๋๋ค
์ถ์ : ์ด ๋ฌธ์ ๋ https://github.com/lostisland/faraday/issues/830#issue -372589645 ๋ฐ https://github.com/lostisland/faraday/issues/769#issue -295426091 ๊ณผ ๊ด๋ จ์ด ์๋ ๊ฒ ๊ฐ์ง๋ง ์ ๋ ํด๊ฒฐ์ฑ ์ ์ฐพ์ ์ ์์ต๋๋ค. ๋์์ฃผ์ธ์..
๋ฌธ์ ๋ ํ์ด๋ก๋๊ฐ ๊ตฌ์ฑ๋๋ ๋ฐฉ์์ ์์ต๋๋ค. curl -data-binary
์ค๋ํซ์ ๋ฐ๋ฅด๋ฉด ์๋ฒ๋ message
์์ ๊ฐ์ด application/json
์ฝํ
์ธ ์ ํ์ ๊ฐ๊ธฐ๋ฅผ ์ํฉ๋๋ค. ๊ทธ๋ฌ๋ ๊ตฌ์ฑ๋ ํ์ด๋ก๋๋ ์ด๊ฒ์ ์ง์ ํ์ง ์์ต๋๋ค.
Faraday v1.0์์ ์์ ํ๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. ๋ฉํฐํํธ ๋ฏธ๋ค์จ์ด ์ ๋ํด ์์ธํ ์์๋ณด๊ธฐโฆ
-payload = {message: JSON.dump(message)}
+payload = { message: Faraday::ParamPart.new(JSON.dump(message), โapplication/jsonโ) }
ํจ๋ฌ๋ฐ์ด v0.1x(0.17.3์์ ํ์ธ). ์ด๊ฒ์ ์ฌ์ ํ โโ๋ฉ๋ชจ๋ฆฌ ๋ด IO ๊ฐ์ฒด์์ ์ฝ๋ "ํ์ผ"์ ๋ณด๋ ๋๋ค. ์๋ฒ๊ฐ ์ถ๊ฐ ๋ฉํฐํํธ ํค๋ ๊ฐ์ ์ ๊ฒฝ ์ฐ์ง ์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค. ์ด ๋ฉ์์ง ํ๋จ์ 3์ฐจ ์์ฒญ์์ ์์ธํ ๋ด์ฉ์ ํ์ธํ ์ ์์ต๋๋ค.
-payload = {message: JSON.dump(message)}
+{ message: Faraday::UploadIO.new(StringIO.new(JSON.dump(message)), 'application/json') }
์๋ฒ๊ฐ ์๋ตํ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์ด๋ป๊ฒ ์ฒ๋ฆฌํด์ผ ํ ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
์ฝํ ์ธ ์ ํ 'application/octet-stream'์ ์ง์๋์ง ์์ต๋๋ค.
application/octet-stream
์ ์ถ์ฒ๋ฅผ ์ ์ ์๊ธฐ ๋๋ฌธ์ ๋ฉํฐํํธ ์ฝํ
์ธ ์ ํ ๋ฌธ์ ๋ฅผ ์์ ํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.
๋ ๊ถ๊ธํ ์ ์ด ์์ผ๋ฉด ์๋ ค์ฃผ์ธ์!
multipart.rb ยท GitHub ์์ ์๋ํ๋ ์ฝ๋ ์กฐ๊ฐ์ ๋ณผ ์ ์์ต๋๋ค. ์ฝ๋๊ฐ ์ฐธ์กฐ ํ๋ RequestBin ์ ์ผ์์ ์ผ๋ก ์์ฒญ ์ ๋ณด๋ง ๋ณด์ ํ๋ฏ๋ก ์๋์ ์ธ๋ถ ์ ๋ณด๋ฅผ ๊ธฐ๋กํ๊ณ ์์ต๋๋ค.
ํ์ด๋ก๋์ ์ฝํ ์ธ ์ ํ์ด ์๋ ์์ฒญ:
# AMZ/Cloudfront headers removed
Content-Type: multipart/form-data; boundary=โโโโโRubyMultipartPost-10fbc5eb433c89c0eca87785f09ae45d
Connection: close
Connect-Time: 1
X-Request-Id: e802a260-56a9-4d01-a4ee-77f652380185
Content-Length: 253
Host: requestbin.io
User-Agent: Faraday v1.0.0
Accept: */*
โโโโโโRubyMultipartPost-10fbc5eb433c89c0eca87785f09ae45d
Content-Disposition: form-data; name=โmessageโ
{โtitleโ:โtitleโ,โbody":"body of messageโ,โrecipientIdList":[186554]}
โโโโโโRubyMultipartPost-10fbc5eb433c89c0eca87785f09ae45dโโโโโโ
WITH ์ฝํ ์ธ ์ ํ ์์ฒญ(Faraday 1.0)
Content-Type: multipart/form-data; boundary=โโโโโRubyMultipartPost-9d77ee5700e0658dddb09ac41fad5fa4
Connection: close
Connect-Time: 0
Content-Length: 285
User-Agent: Faraday v1.0.0
X-Request-Id: 2bbb3705-42ec-4de2-877c-2afd588ed679
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Host: requestbin.io
โโโโโโRubyMultipartPost-9d77ee5700e0658dddb09ac41fad5fa4
Content-Disposition: form-data; name=โmessageโ
Content-Type: application/json
{โtitleโ:โtitleโ,โbody":"body of messageโ,โrecipientIdListโ:[186554]}
โโโโโโRubyMultipartPost-9d77ee5700e0658dddb09ac41fad5fa4โโโโโโ
WITH ์ฝํ ์ธ ์ ํ ์์ฒญ(Faraday v0.17.3)
Content-Type: multipart/form-data; boundary=โโโโโRubyMultipartPost-697c8614200bc0d7ae2fcc0215a2a697
Connection: close
Content-Length: 363
User-Agent: Faraday v0.17.3
X-Request-Id: af65fc06-3914-4ab6-8dbf-b347a1ac498a
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Host: requestbin.io
โโโโโโRubyMultipartPost-697c8614200bc0d7ae2fcc0215a2a697
Content-Disposition: form-data; name=โmessageโ; filename=โlocal.path"
Content-Length: 69
Content-Type: application/json
Content-Transfer-Encoding: binary
{โtitleโ:โtitleโ,โbodyโ:โbody of messageโ,โrecipientIdListโ:[186554]}
โโโโโโRubyMultipartPost-697c8614200bc0d7ae2fcc0215a2a697โ
๋์์ ์ฃผ์
์ ๋๋จํ ๊ฐ์ฌํฉ๋๋ค, @technoweenie ! ๋น์ ์ ๊ต์ฅํ๋ค!!
์ด์ ์์ฒญ์ ์๋ก ๊ตฌ์ฑ๋ ํ์ด๋ก๋์์ ์ ๋๋ก ์๋ํ๋ฉฐ ๋ ์ด์ application/octet-stream
์ ๋ํด ๋ถํํ์ง ์์ต๋๋ค.
์ข์ ํ๋ฃจ ๋ณด๋ด์๊ธฐ ๋ฐ๋๋๋ค :D
์ด์ ์์๋๋ก ์๋ํ๋ค๋ ์์์ ๋ค์ผ๋ ๊ธฐ์ฉ๋๋ค!
์๊ณ ํ์
จ์ต๋๋ค @technoweenie , ์ด ๊น๋ค๋ก์ด ๋ฌธ์ ๋ฅผ ๋นจ๋ฆฌ ํด๊ฒฐํด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค ๐ !
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ฌธ์ ๋ ํ์ด๋ก๋๊ฐ ๊ตฌ์ฑ๋๋ ๋ฐฉ์์ ์์ต๋๋ค.
curl -data-binary
์ค๋ํซ์ ๋ฐ๋ฅด๋ฉด ์๋ฒ๋message
์์ ๊ฐ์ดapplication/json
์ฝํ ์ธ ์ ํ์ ๊ฐ๊ธฐ๋ฅผ ์ํฉ๋๋ค. ๊ทธ๋ฌ๋ ๊ตฌ์ฑ๋ ํ์ด๋ก๋๋ ์ด๊ฒ์ ์ง์ ํ์ง ์์ต๋๋ค.Faraday v1.0์์ ์์ ํ๋ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. ๋ฉํฐํํธ ๋ฏธ๋ค์จ์ด ์ ๋ํด ์์ธํ ์์๋ณด๊ธฐโฆ
ํจ๋ฌ๋ฐ์ด v0.1x(0.17.3์์ ํ์ธ). ์ด๊ฒ์ ์ฌ์ ํ โโ๋ฉ๋ชจ๋ฆฌ ๋ด IO ๊ฐ์ฒด์์ ์ฝ๋ "ํ์ผ"์ ๋ณด๋ ๋๋ค. ์๋ฒ๊ฐ ์ถ๊ฐ ๋ฉํฐํํธ ํค๋ ๊ฐ์ ์ ๊ฒฝ ์ฐ์ง ์๊ธฐ๋ฅผ ๋ฐ๋๋๋ค. ์ด ๋ฉ์์ง ํ๋จ์ 3์ฐจ ์์ฒญ์์ ์์ธํ ๋ด์ฉ์ ํ์ธํ ์ ์์ต๋๋ค.
์๋ฒ๊ฐ ์๋ตํ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ์ด๋ป๊ฒ ์ฒ๋ฆฌํด์ผ ํ ์ง ๋ชจ๋ฅด๊ฒ ์ต๋๋ค.
application/octet-stream
์ ์ถ์ฒ๋ฅผ ์ ์ ์๊ธฐ ๋๋ฌธ์ ๋ฉํฐํํธ ์ฝํ ์ธ ์ ํ ๋ฌธ์ ๋ฅผ ์์ ํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋๊ธฐ๋ฅผ ๋ฐ๋๋๋ค.๋ ๊ถ๊ธํ ์ ์ด ์์ผ๋ฉด ์๋ ค์ฃผ์ธ์!
๋ด ์์ ํ์
multipart.rb ยท GitHub ์์ ์๋ํ๋ ์ฝ๋ ์กฐ๊ฐ์ ๋ณผ ์ ์์ต๋๋ค. ์ฝ๋๊ฐ ์ฐธ์กฐ ํ๋ RequestBin ์ ์ผ์์ ์ผ๋ก ์์ฒญ ์ ๋ณด๋ง ๋ณด์ ํ๋ฏ๋ก ์๋์ ์ธ๋ถ ์ ๋ณด๋ฅผ ๊ธฐ๋กํ๊ณ ์์ต๋๋ค.
ํ์ด๋ก๋์ ์ฝํ ์ธ ์ ํ์ด ์๋ ์์ฒญ:
WITH ์ฝํ ์ธ ์ ํ ์์ฒญ(Faraday 1.0)
WITH ์ฝํ ์ธ ์ ํ ์์ฒญ(Faraday v0.17.3)