python - Using Urllib instead of action in post form -


I have to allow users to upload content directly to Amazon S3. This form works:

  & lt; Form action = "https://me.s3.amazonaws.com/" method = "post" enctype = 'multipart / form-data' class = "upload-form" & gt; {% Csrf_token%} & lt; Input type = "hidden" name = "key" value = "video / test.jpg" & gt; & Lt; Input type = "hidden" name = "AWSAccessKeyId" value = "& lt; access_key & gt;" & Gt; & Lt; Input type = "hidden" name = "ACL" value = "public-read" & gt; & Lt; Input type = "hidden" name = "policy" value = "{{policy}}" & gt; & Lt; Input type = "hidden" name = "signature" value = "{{sign}}" & gt; & Lt; Input type = "hidden" name = "content-type" value = "image / jpeg" & gt; & Lt; Input type = "submit" value = "upload" name = "upload" & gt; & Lt; / Form & gt;   

And in the function, I define the policy and signature. However, I need to pass two variables in the form - content-type and key , which will only be known when users press the upload button. Thus, I need to pass these two variables on the template after the POST request, but before the direction of Amazon again.

It was suggested that I use urlib to do this. I have tried to do this in the following manner, but I currently have an inscrutable HTTPError I currently have:

  if request.method == 'POST': # variable urllib2.urlopen (" Define urlib. Urlencode ('(' key ',' video / test3.jpg '), (' AWSAccessKeyId ',' & lt; access_key '), (' acl ' , 'Public-read'), ('policy', policy) '' signature '', signature), ('content-type', content-type), ('file', file)])  / Pre> 

I have tried to harsh all the values ​​instead of using the variable but Also also get the same error whether I'm in the wrong way and I need you to change to be able to redirect the form in the Amazon, the content can be directly uploaded to the Amazon?

I see the form with its function, enable and set on the Net tab.

After completing POST, click on its [+] icon to expand it, study the Headers, Posts, Response tab, what you are missing and / or doing wrong .

Separate this script from the next regions and insert a standalone file. Add one thing at a time and do not touch it again till it works. The lines below should increase visibility in your script.

  import httplib httplib.HTTPConnection.debuglevel = 1   

I tried to roam myself with urlib, but as I have somebody on AWS I do not have an account 400 400. Bad request does not come forward in addition to receiving a response sounds like a good sign, maybe I need a valid host and key parameter etc.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -