File uploading support

371 views
Skip to first unread message

Stanislav Feldman

unread,
Mar 11, 2011, 3:12:05 AM3/11/11
to ChicagoBoss
How can I upload file via CB?

Evan Miller

unread,
Mar 11, 2011, 10:03:09 AM3/11/11
to chica...@googlegroups.com
Try Req:post_files(). I think it will give you a list of temporary
files in the POST request.

On Fri, Mar 11, 2011 at 2:12 AM, Stanislav Feldman
<stanisla...@gmail.com> wrote:
> How can I upload file via CB?

--
Evan Miller
http://www.evanmiller.org/

Kai Janson

unread,
Oct 24, 2011, 7:11:44 PM10/24/11
to chica...@googlegroups.com
Hi Evan,

I use Req:post_files() but it is always empty.
Do I need to do something in my (html) form ?

Please advise.

--Kai

Evan Miller

unread,
Nov 13, 2011, 2:47:37 PM11/13/11
to chica...@googlegroups.com
Hmm, this works for me. Make sure that the server can write to the "scratch" directory of your project.

Kai Janson

unread,
Nov 13, 2011, 2:56:07 PM11/13/11
to chica...@googlegroups.com
Hi Evan,

Yes, it works.  Sorry I forgot to put some additional info after I got it to work.

<form method="post" enctype="multipart/form-data">

That's the key.  After that it works like magic.
I really enjoy the fact that the uploaded files are stored in scratch, and that the entire information about the file is available
as a result, but the filename is a pain :)

Anyhow, it works.

--Kai

egos...@gmail.com

unread,
Aug 19, 2013, 6:20:53 PM8/19/13
to chica...@googlegroups.com
Hi, guys , can somone show a sampl how to get the contents of a file , from i get the temp file names to teading the content - i am now to erlang and this framework.

egos...@gmail.com

unread,
Aug 19, 2013, 7:32:21 PM8/19/13
to chica...@googlegroups.com
hage been the nube, but i got at far as Req:post_files(), its been stuck there for days now, sigh,,,,,i can't get to the file.
any complete examples?


On Friday, March 11, 2011 4:12:05 AM UTC-4, Stanislav Feldman wrote:

Graeme Defty

unread,
Aug 20, 2013, 1:26:16 PM8/20/13
to chica...@googlegroups.com
Not exactly a complete example, but code from my (working) application . . . . .

    [{uploaded_file, FileName, Location, Length}] = Req:post_files(),
    Fname = "./priv/static/lb/headers/" ++ FileName,
    file:copy(Location, Fname),
    file:delete(Location),

Hope this helps a bit

g




--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

till haxor

unread,
Mar 3, 2014, 10:24:05 PM3/3/14
to chica...@googlegroups.com
no way to save a file from cb_admin?

something like this (it's just an invention)

152                 'POST' ->
153                     Record = lists:foldr(fun
154                                 ('id', Acc) -> Acc:set(id, 'id');
155                                 (Attr, Acc) ->
156                                     AttrName = atom_to_list(Attr),
157                                     Val = Req:post_param(AttrName),
158                                     [{_, FileName, Location, Length}] = Req:post_files(),
159                                     Val1 = case erlang:length(FileName) > 0 of
160                                                true ->
161                                                    Fname = "./priv/static/" ++ FileName,
162                                                    file:copy(Location, Fname),
163                                                    file:delete(Location),
164                                                    Fname;
165                                                _ -> Req:post_param(AttrName)
166                                            end,
167                                     Acc:set(Attr, Val1)
168                             end, DummyRecord, DummyRecord:attribute_names()),



Reply all
Reply to author
Forward
0 new messages