Skip to content

Instantly share code, notes, and snippets.

@etrepum
Created March 4, 2009 01:27
Show Gist options
  • Save etrepum/73654 to your computer and use it in GitHub Desktop.
Save etrepum/73654 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