Skip to content

Instantly share code, notes, and snippets.

@ngerakines
Forked from etrepum/gist:73654
Created March 4, 2009 02:16
Show Gist options
  • Save ngerakines/73668 to your computer and use it in GitHub Desktop.
Save ngerakines/73668 to your computer and use it in GitHub Desktop.
pastebin_dropbox(Path) ->
fun ("", _) ->
fun pastebin_devnull/1;
(Filename, _ContentType) ->
Date = fmt_date(date()),
RelName = filename:join([Date,
mochicode:url64_encode(term_to_binary(now())),
filename:basename(Filename)]),
AbsName = filename:join([Path, RelName]),
ok = filelib:ensure_dir(AbsName),
{ok, IoDevice} = file:open(AbsName, [write]),
fun (Next) ->
pastebin_dropbox(Next, RelName, IoDevice)
end
end.
pastebin_devnull(eof) ->
"";
pastebin_devnull(_) ->
fun pastebin_devnull/1.
pastebin_dropbox(eof, RelName, IoDevice) ->
ok = file:close(IoDevice),
{file, RelName};
pastebin_dropbox(Data, RelName, IoDevice) ->
ok = file:write(IoDevice, Data),
fun (Next) -> pastebin_dropbox(Next, RelName, IoDevice) end.
%% call site looks something like this
'POST' ->
case Path of
"pastebin" ++ _ ->
PostList = case Req:get_primary_header_value("content-type") of
"multipart/form-data" ->
mochiweb_multipart:parse_form(
Req,
pastebin_dropbox(
filename:join(DocRoot, "dropbox")));
_ ->
Req:parse_post()
end,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment