Commits

Anonymous committed 79def84

add find_boundary/1 courtesy of Andy Gross

  • Participants
  • Parent commits 559437a

Comments (0)

Files changed (1)

src/webmachine_multipart.erl

 %% @author Justin Sheehy <justin@basho.com>
+%% @author Andy Gross <andy@basho.com>
 %% @copyright 2009 Basho Technologies
 
 %% @doc Utility for parsing multipart form bodies.
 
 -module(webmachine_multipart).
 -author('Justin Sheehy <justin@basho.com>').
--export([get_all_parts/2,stream_parts/2]).
+-author('Andy Gross <andy@basho.com>').
+-export([get_all_parts/2,stream_parts/2, find_boundary/1]).
 -export([test_body/0,test_body2/0]).
 
 % @type incoming_req_body() = binary().
 % @type fcontent() = binary().
 % The body content within a form part.
 
+% @doc Find the multipart boundary for a request.
+% @spec find_boundary(wrq:wm_reqdata()) -> boundary()
+find_boundary(ReqData) ->
+    ContentType = wrq:get_req_header("content-type", ReqData),
+    string:substr(ContentType, string:str(ContentType, "boundary=") 
+                  + length("boundary=")).
+
 % @doc Turn a multipart form into component parts.
 % @spec get_all_parts(incoming_req_body(), boundary()) -> [fpart()]
 get_all_parts(Body, Boundary) when is_binary(Body), is_list(Boundary) ->