views:

169

answers:

1

I have written a tiny web appication in python that allows me to browse my S3 buckets. The web appication runs inside the Google App Engine.

Now, I want to create a html form for this web appication that allows me to upload a file into the bucket.

These information are already inside the form: AWSAccessKeyId and the name of the bucket.

I want that the keyname is the name of the file that is selected by the user via <input name="file" type="file">

Another problem is: Can I create the content of the (hidden) input tags policy and signature before a file is choosen?

I want to solve this problem only with HTML and Python. No JavaScript.

Is this possible?

+3  A: 

Read the developer documentation from Amazon: Browser Uploads to S3 using HTML POST Forms

There is Python examples in there to get you started.

The Matt
I know this document. But I still have one problem.I need two steps to upload a file to S3. First, I have the HTML form where the file is selected. Second, I need to Base64-encode the policy document and calculate a signature value with python. These values are included into the html form(?) and then the user has to send the document again. The user has need to "send" the file two times?
Neverland
Read the section on the `key` field name again. You can use the special token `${filename}` to have S3 set the filename the user is uploading, so there is no need to send the file twice. You only have to sign the form once and can use it over and over again until you hit the expiration date you set.
dar
Now, I have this line inside my policy document: ["eq", "$key", "${filename}"]. But the result is: AccessDenied: Invalid according to Policy: Policy Condition failed: ["eq", "$key", ""]
Neverland
I think you need the literal ${filename} token in the key. Your code appears to be treating that as an empty variable, which is why you see no value when it throws the error ["eq", "$key", ""].
The Matt