views:

45

answers:

1

I'm trying to upload a file with curl, but I keep running into this one error.

AttributeError: 'unicode' object has no attribute 'file'

I'm on OSX, and the curl command im using looks like this:

curl -d "attach=@`pwd`/output.txt" http://localhost:8081

The app engine code looks like this which is taken from the image share example app.

def post(self):
  attachment = self.request.POST.get('attach').file.read()

I'm thinking I may be missing some params regarding the file in the curl command? When I add "type=text/plain" I just get a new error.

AttributeError: 'str' object has no attribute 'file'

I also looked at the blobstore, but this file upload is just going to be passed off onto a mail attachment, so I would rather not have to save the upload to disk.

Edit: I just tried the example in this other question and I get a unicode error, so I convert it to a string, but it doesn't give me the file, just the string that is the path to the file.

A: 

Use the -F parameter of curl instead of -d, the same way you do it with in your post:

curl -F "attach=@`pwd`/output.txt" http://localhost:8080

(Background: with -d what you got was the file path (parsed on the server side as a unicode object), not the file contents)

Jacob Oscarson