upload using restful

219 views
Skip to first unread message

Jose

unread,
Nov 24, 2015, 8:11:41 AM11/24/15
to web2py-users
Hi

How I can upload a file using RESTful api?

Jose
Message has been deleted

Leonel Câmara

unread,
Nov 24, 2015, 11:24:49 AM11/24/15
to web2py-users

Jose

unread,
Nov 24, 2015, 11:33:20 AM11/24/15
to web2py-users
Hi Leonel

How it is handled on the server (web2py app)?

Dave S

unread,
Nov 24, 2015, 2:21:05 PM11/24/15
to web2py-users


On Tuesday, November 24, 2015 at 8:33:20 AM UTC-8, Jose wrote:
Hi Leonel

How it is handled on the server (web2py app)?

Does this help explain it?

<URL:http://web2py.com/books/default/chapter/29/10/services#Restful-Web-Services>

I've used the SOAP service model successfully -- the RESTful subset, anyway -- but haven't done a pure REST service yet, but the book has a good description and you should be able to find some threads in the group archives with additional examples.

/dps
 

Dave S

unread,
Jan 22, 2016, 3:18:08 PM1/22/16
to web2py-users
I can now answer in more detail, as I've actually done it now.

After doing an upload page based on  the Image Blog example in Chapter 3, I moved on to RESTing on curl.  The Chapter 10 material was helpful, as was Chapter 6 under "More on uploads".

The archive has some older posts that helped me, and actually pushed me across the finish line:

Date: Wed, 15 Feb 2012 12:25:24 +0000
Subject: Re: [web2py] Re: can we use JSONRPC to upload?
(From Antonio Ramos)

Subject: Re: [web2py] Re: Auto-generate PUT and DELETE methods
Date: Wed, 20 Jun 2012 20:42:17 -0700 (PDT)
(From Massimo)

Date: Thu, 10 Sep 2009 13:36:13 -0700 (PDT)
Subject: Re: Database administration - db upload field
From: mdipierro <mdip...@cs.depaul.edu>
(Massimo, earlier)


I'm using cStringIO.StringIO on the request data, but I'm sending binary (curl -H "Contnt-Type: application/octet-stream"), and the file is stored in uploads with a .txt extension, which makes Firefox think it should maybe open it with gedit (when right clicking from the appadmin page).  Saving the download to a file is okay, and I can untar a tar file, and another binary file compares okay, but it would be nice to get the type correct on download.

Also, I had to the use the "def POST(*args, **vars)" form, and couldn't figure out how to do it the parse_as_restfull() technique, partly because I couldn't figure out the URL and curl invocation to handle the file data.  Furthermore, the curl -T doesn't seem to be putting the local filename into the POST, whereas the SQLFORM does.  I have an fname field, which is redundant in the SQLFORM version, but is what I use in the RESTful upload.

So I finally did Yet Another Web2Py Trick.  The SQLFORM version took me half an hour or less, and then I broke things for a while trying to see what the POST url looked like, and then spent the rest of the afternoon on the REST.

/dps "YAW2PT-count++"

Reply all
Reply to author
Forward
0 new messages