Anonymous avatar Anonymous committed 79def84

add find_boundary/1 courtesy of Andy Gross

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) ->
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.