views:

680

answers:

3

The AppEngine's standard API assumes files are uploaded from an HTML form. I'm trying to post a file to the blobstore from a REST API method that can be called by a non Html client (Flash, iPhone, etc.)

The code I'm trying to get working:

# Get the blobstore upload url    
upload_url = blobstore.create_upload_url("/activities/upload_finished");

# Make sync call to the blobstore url to post our image
result = urlfetch.fetch(url=upload_url,
                        payload=request.FILES,
                        method=urlfetch.POST,
                        headers={'Content-Type': 'multipart/form-data'})

I'm getting the following error:

ValueError: Invalid boundary in

Any idea?
Has anyone tried posting to the blobstore not through a web form?

multipart form: ''

+2  A: 

You can't make a regular post into a multipart form simply by specifying the content type - you're just submitting URL-encoded data with the wrong content type.

You'll need to assemble a proper multipart form - using the email module or by hand, like this.

Also see this question.

Nick Johnson
A: 

Does anybody know if this is a reliable way of exposing the blobstore to a RESTful API? What were your experiences with it?

epoch
thats exactly the problem... you cantyou can only put data in it via a web form
Eran Kampf
Yes indeed, I was wondering if there was a workaround that meant posting data to a API URL and then reposting to a special URL created by the blobstore?
epoch
+1  A: 

I have the same need and I don't like all the suggested solutions which are:

  1. Define an endpoint that will return the upload url
  2. Use urlfetch to transfer the data from the endpoint to the upload url

I opened an issue for it (Static endpoint for blobstore upload) which I encourage everyone with the same need to star the issue and maybe it will be bumped up in the priority.

Shay Erlichmen