Permalink
Browse files

Add uploaded_file API module and docs

  • Loading branch information...
1 parent 1c79cb1 commit 11935b91fbafd7a3525b02f9a2bbd7177449944f @choptastic choptastic committed Mar 21, 2013
Showing with 43 additions and 1 deletion.
  1. +12 −1 README.markdown
  2. +31 −0 src/uploaded_file.erl
View
@@ -77,10 +77,20 @@ Once you have created the request bridge object (a parameterized module), it pro
* *Bridge:cookies()* - returns a proplist of cookies, [{"Cookie1", "Value1"}, {"Cookie2", "Value2"}, ...]
* *Bridge:query_params()* - returns a proplist of query params, [{"Query1", "Value1"}, {"Query2", "Value2"}, ...]
* *Bridge:post_params()* - returns a proplist of post params, [{"Post1", "Value1"}, {"Post2", "Value2"}, ...]
-* *Bridge:post_files()* - returns a list of upload_file records, describing the files uploaded in a multipart post.
+* *Bridge:post_files()* - returns a list of `#uploaded_file` records, describing the files uploaded in a multipart post.
* *Bridge:request_body()* - returns the request body that has been read so far, as a list.
* *Bridge:error()* - returns an Erlang term describing any errors that happened while parsing a multipart post.
+<h3>Uploaded File Interface</h3>
+
+`Bridge:post_files()` returns a list of `#uploaded_file` records, but it's inconvenient to have to include the `simple_bridge.hrl` header in your application's modules. The safer and more portable approach is to use the `uploaded_file` module provided by Simple Bridge.
+
+`uploaded_file` exports the following functions:
+
+* *UploadedFile:original_name()* - The original name of the file from the user's system
+* *UploadedFile:temp_name()* - The temporary name for the file as it's stored on the server.
+* *UploadedFile:size()* - The size of the file in bytes
+* *UploadedFile:field_name()* - The name of the HTML `<input type=file>` element from the page.
<h3>What modules are involved in a request bridge?</h3>
@@ -93,6 +103,7 @@ Once you have created the request bridge object (a parameterized module), it pro
* *yaws_request_bridge.erl* - The request bridge module for Yaws.
* *misultin_request_bridge.erl* - The request bridge module for Misultin.
* *???_request_bridge.erl* - Support for more servers on the way.
+* *uploaded_file.erl* - API to access information about an uploaded file.
To extend the SimpleBridge to work with other HTTP servers (or other versions of Inets, Mochiweb, or Yaws), copy and modify inets_request_bridge.erl or mochiweb_request_bridge.erl.
View
@@ -0,0 +1,31 @@
+%% vim: ts=4 sw=4 et
+% Simple Bridge
+% Copyright (c) 2013 Jesse Gumm
+% See MIT-LICENSE for licensing information.
+%
+% uploaded_file provides an API to the uploaded_file record without having to
+% include simple_bridge.hrl file into user applications.
+%
+% This can be called either in standard Erlang:
+% uploaded_file:original_name(File).
+%
+% Or in parameter module (assuming future version of Erlang still support it):
+% File:original_name().
+%
+-module(uploaded_file).
+-include("simple_bridge.hrl").
+-compile({no_auto_import,[size/1]}).
+
+-export([
+ original_name/1,
+ temp_file/1,
+ size/1,
+ field_name/1]).
+
+original_name(#uploaded_file{original_name=N}) -> N.
+
+temp_file(#uploaded_file{temp_file=N}) -> N.
+
+size(#uploaded_file{size=S}) -> S.
+
+field_name(#uploaded_file{field_name=N}) -> N.

4 comments on commit 11935b9

tex commented on 11935b9 May 4, 2013

Just a general complain on lack of namespaces in erlang... I have a module with exactly same name in my project so they are now colliding. I will eventually rename it in a future but for now I have just renamed simple_bridge's one.... Good lesson for me to always prefix module's name.

Owner
tex replied May 4, 2013

Thanks Jesse. I too admit that my choose of module names wasn't the best. Always prefix my module names :-)

Owner

Thanks Milan,

I've filed this as an issue: nitrogen/nitrogen_core#47 and will have it resolved in the next release.

Please sign in to comment.