Created
July 20, 2015 20:18
-
-
Save CurtHagenlocher/b21ce9cddf54e3807317 to your computer and use it in GitHub Desktop.
Revisions
-
CurtHagenlocher created this gist
Jul 20, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ let Web.MultiPartPost = (url as text, parts as record) as binary => let unique = Text.NewGuid(), boundary = "--" & unique, crlf = "#(cr)#(lf)", item = (name, value) => let filename = Value.Metadata(value)[name]?, contentType = Value.Metadata(value)[type]?, line1 = "Content-Disposition: form-data; name=""" & name & """" & (if filename = null then "" else "; filename=""" & filename & """"), line2 = if contentType = null then {} else { "Content-Type: " & contentType }, lines = { boundary, line1 } & line2 & { "", value } in Text.Combine(lines, crlf) & crlf, body = Text.Combine(List.Transform(Record.FieldNames(parts), each item(_, Record.Field(parts, _)))) & boundary & "--" & crlf in Web.Contents(url, [ Headers=[#"Content-Type"="multipart/form-data; boundary=" & unique], Content=Text.ToBinary(body) ]), fileContents = "{""code"": ""15315""} {""code"": ""526133""} {""code"": ""43011""} {""code"": ""83988""} {""code"": ""182347""}", parts = [ id = "c9c43e63-9372-441c-9ab7-c5e66d7da371", file = fileContents meta [name="upload.txt", type="text/plain"], locale = "en-US" ], Result = Web.MultiPartPost("http://foo.com/bar/baz", parts) in Result