Amazon S3 Upload What Key Does

I am really confused by the fact that the key value should be when using amazon s3 here - this is my code.

   <form action="http://bucket.s3.amazonaws.com" method="post" enctype="multipart/form-data">
<input type="text" name="key" value="{filename}" />
<input type="text" name="acl" value="public-read" />
<input type="text" name="content-type" value="text/plain" />
<input type="hidden" name="AWSAccessKeyId" value="Amazon Key" />
<input type="hidden" name="policy" value="ewogICJleHBpcmF0aW9uIjogIjIwMTItMDEtMDFUMTI6MDA6MDAuMDAwWiIsCiAgImNvbmRpdGlvbnMiOiBbCiAgICB7ImJ1Y2tldCI6ICJpcIHsiYWNsIjogInB1YmxpYy1yZWFkIiB9LAogICAgWyJlcSIsICIka2V5IiwgIntmaWxlbmFtZX0iXSwKICAgIFsic3RhcnRzLXdpdGgiLCAiJENvbnRlbnQtVHlwZSIsICJ0ZXh0LyJdLAogIF0KfQo=" />
<input type="hidden" name="signature" value="fGWi1jKU+hKZKbCIL1eD0=" />
<input name="file" type="file" />
<input name="submit" value="Upload" type="submit" />
</form>

Good, that’s why I use this service to create my policy, etc., because I don’t know how to do it manually.

http://s3.amazonaws.com/doc/s3-example-code/post/post_sample.html

This works and gives me everything to download. But when I upload my files, they always call {filename}, and not the actual file name says picture.jpg. I know that it comes to this line.

<input type="text" name="key" value="{filename}" />

I want this value to be disconnected from the actual file name that I am loading.

What I am doing wrong is very confused.

I tried to leave it blank, but I get this error.

The InvalidArgumentUser key must be longer than 0

I want this to work for me ????

,

+3
6

, -, - .

- , .

, , . , : ${filename} ( $)

: , /docs/

:

<form action="http://yourbucketname.s3.amazonaws.com" method="post" enctype="multipart/form-data">
<input type="text" name="key" value="docs/${filename}" />
<input type="text" name="acl" value="public-read" />
<input type="text" name="content-type" value="text/plain" />
<input type="hidden" name="AWSAccessKeyId" value="<YourPublicKey>" />
<input type="hidden" name="policy" value="<Base64_encoded_your_policy>" />
<input type="hidden" name="signature" value="<HMAC SHA-1 of the policy>" />
<input name="file" type="file" />
<input name="submit" value="Upload" type="submit" />
</form>

JSON

{"expiration": "2013-12-01T12:00:00.000Z",
"conditions": [
{"acl": "public-read-write" },
{"bucket": "yourbucketname" },
["starts-with", "$key", "docs/"],
["starts-with", "$Content-Type", "text/plain"],
]
}

:

+6

$ {filename}. :

<input type="text" name="key" value="${filename}" />

. http://docs.amazonwebservices.com/AmazonS3/latest/dev/HTTPPOSTForms.html.

+2

{filename}

+1

-, , , API Amazon EC2. . -, - :

com.amazonaws.services.ec2.util.S3UploadPolicy
+1

"" - . .

0

, HTML- : article , . article , , .

script, , base64.

IMP: , policy.json

import base64
import hmac, hashlib
import os
AWS_SECRET_ACCESS_KEY = 'Your Access Key'

os.system('clear')
print "This policy generator is for key : " + AWS_SECRET_ACCESS_KEY  
print "Make sure this is the correct key."
print "IMP: Please be consistent with the file policy.json small changes in space or newline can fail policy"

policy_document = file("policy.json",'rb').read()
policy = base64.b64encode(policy_document)
signature = base64.b64encode(hmac.new(AWS_SECRET_ACCESS_KEY, policy, hashlib.sha1).digest())

print
print "Policy (BASE64_POLICY to be inserted in HTML):-"
print policy
print
print "Signature:-"
print signature
print

policy.json, :

{
  "expiration": "2014-01-01T00:00:00.00Z",
  "conditions": [
    {"bucket": "BUCKET NAME" },
    ["starts-with", "$key", "PREFIX_IF_ANY"],
    {"acl": "public-read" },
    {"success_action_redirect": "http://REDIRECTED_URL" },
    ["starts-with", "$Content-Type", "CONTENT_TYPE"],
    ["content-length-range", 0, 1048576],
  ]
}

HTML :

<html> 
    <head>
        <title>S3 POST Form</title> 
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </head>

    <body> 
        <form action="http://BUCKET_NAME.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
            <input type="hidden" name="key" value="picbum/${filename}">
            <input type="hidden" name="AWSAccessKeyId" value="AccessID"> 
            <input type="hidden" name="acl" value="public-read"> 
            <input type="hidden" name="success_action_redirect" value="http://REDIRECTED_URL">
            <!-- Fill these HTML fields with data generated from python script -->
            <input type="hidden" name="policy" value='BASE64_POLICY'>
            <input type="hidden" name="signature" value="SIGNATURE_GENERATED">
            <input type="hidden" name="Content-Type" value="CONTENT_TYPE">
            <!-- Include any additional input fields here -->

            File to upload to S3: 
            <input name="file" type="file"> 
            <br> 
            <input type="submit" value="Upload File to S3"> 
        </form> 
    </body>
</html>
0

Source: https://habr.com/ru/post/1787692/


All Articles