Uploading file through restful webservice

205 views
Skip to first unread message

Raj Chinna

unread,
Nov 20, 2013, 10:12:28 AM11/20/13
to web...@googlegroups.com
Hi,

I am new to web2py and currently built a restful webservice that accepts data from my client (Android Application) and stores the data into the DB. But, due to business need I need to send a text file from the client and the server needs to store it in server file system. Can someone give me a pointer on how to implement file handling in web2py restful service?

I did search through web2py docs and groups but couldn't find any relevant answer. kindly help me with a pointer.

Thanks in Advance

Raj Chinna

unread,
Nov 20, 2013, 11:43:22 PM11/20/13
to web...@googlegroups.com
Can someone give me a pointer.. I am waiting for the response..

Eduardo Cruz

unread,
Nov 21, 2013, 7:25:28 AM11/21/13
to web...@googlegroups.com
Web2Py Book: Uploads

You could do something like
import StringIO

myfile = StringIO.StringIO()
myfile
.write(yourtextfile)
being "yourtextfile"  the text-file you sent from the client(which would be actually a huge string)
then do something like
db.mytable.insert(file=db.mytable.file.store(myfile, "filename"))

Raj Chinna

unread,
Dec 19, 2013, 1:29:52 AM12/19/13
to web...@googlegroups.com
Hi Eduardo,

Thanks for the response. 

Is it something like this, the file that I will be sending from client will come as a huge string and I need to handle it in the below mentioned way? 

I am confused about, who will convert the file into sting and send it.
Reply all
Reply to author
Forward
0 new messages