howto use "file.upload"?

posted by matjes
Posted on Monday December 22, 2008 at 13:54. 309 visits. ( permalink )
I would like to allow my (python-) desktop app to upload files to Ipernity. For most Ipernity function, I used so far, I got my code working (including signature ..).

However the "upload.file" method for me does not work. I have no idea how to include the file data! Should the "file" parameter contain the file name or the file data itsself? Or do I have to upload the file in a way like it is explained here: code.activestate.com/recipes/146306. Should the "file" parameter attached to the url like all other parameters or separatly posted as http "content"?

Many thanks in advance

5 Replies

A Christophe Ruelle pro says:
Hello matjes, yes, the "file" data has to be send like in code.activestate.com/recipes/146306 .
The file will be sent just like any other parameters, but omitted in the signature calculation. All parameters are sent using HTTP POST.
Posted 12 months ago. ( permalink )
matjes says:
Well I still could not manage it. In the API documentation it is written, that the "file" parameter should be send as "url encoded". However "code.activestate.com/recipes/146306" describes how to send it as binary.

I tried the following python code snippet:


def sendPostQuery(self, method, **params):
params = params.copy()
params["api_key"] = self.api_key

if "file" in params:
File = params.pop("file")
if isinstance(File, (str, unicode)):
File = file(File, "rb")
body = urllib.urlencode({ "file" : File.read() })
else:
body = None

query = urllib.urlencode(params)
query = "/api/%s/%s?%s" % (method, self.format, query)
self.conn.request('POST', query, body=body)


However I get the message that 'API Key is missing'.

Have you any useful advises? Many thanks in advance!

Matjes
Posted 12 months ago. ( permalink )
A Christophe Ruelle pro replies:
I don't think the file need to be urlencoded.
All the parameters must be sent using POST - and the signature is calculed without the file.
The POST must be with enctype=multipart/form-data (it's similar to multipart mime).
We're using CURL to do the job, maybe check the PHP API class for an example - or check www.vivtek.com/rfc1867.html
Posted 11 months ago. ( permalink )
ِِِ says:
I didn't ever work with python but i guess the problem is that only the value of the param must be urlencoded ! but you are encoding also the keys!
query = urllib.urlencode(params)
body = urllib.urlencode({ "file" : File.read() })

I hope that this will help, and as Christophe said; take a look at the PHP KIT it work well

regards
Posted 11 months ago. ( permalink )
A Christophe Ruelle pro replies:
Maybe try to use Curl with python...
Posted 11 months ago. ( permalink )

You must be logged on to post a reply. Sign in now?


rss Latest comments – Subscribe to the comment feed for this topic.

 

Català | Čeština | 中文 | Deutsch | English | Español | Esperanto | Ελληνικά | Français | Galego | Italiano | Nederlands | Português | Svenska ny | More...