GithubHelp home page GithubHelp logo

Comments (5)

bradleyg avatar bradleyg commented on June 29, 2024 1

Sure, you can call get_upload_params with 3 post params:

POST /s3direct/get_upload_params
type=video/quicktime
filename=filename.mov
dest=s3DirectDestinationFromSettings

Which returns all of the fields required to post directly to S3:

{  
  "policy":"generated-policy",
  "acl":"public-read",
  "signature":"JeEUf7TNFv5qOk3NmKAZaeIRZbk=",
  "form_action":"https://s3-eu-west-1.amazonaws.com/my-bucket",
  "key":"files/filename.mov",
  "Content-Type":"video/quicktime",
  "AWSAccessKeyId":"my-aws-key",
  "success_action_status":"201"
}

You can then post the file directly:

POST https://s3-eu-west-1.amazonaws.com/my-bucket
policy=generated-policy
acl=public-read
signature=JeEUf7TNFv5qOk3NmKAZaeIRZbk=
key=files/filename.mov
Content-Type=video/quicktime
AWSAccessKeyId=my-aws-key
success_action_status=201
file=binary

from django-s3direct.

endline avatar endline commented on June 29, 2024

+1

from django-s3direct.

aTylerRice avatar aTylerRice commented on June 29, 2024

i have this code right now

content_type = "image/JPEG"
key = 'uploads/filename.jpg'
acl = 'public-read'
bucket = None
params_raw = create_upload_data(content_type,key,acl,bucket)

params = { 'policy': params_raw['policy'],'acl':acl,'signature':params_raw['signature'],'key':params_raw['key'],'Content-Type':params_raw['Content-Type'],'AWSAccessKeyId':params_raw['AWSAccessKeyId'],'success_action_status':params_raw['success_action_status'],'file': binary_data}
r = requests.post(params_raw['form_action'],data=params,files=dict(foo='bar')) 
return JsonResponse({'request':str(r.text)},safe=False)

but for some reason I am getting back
{"request": "\nInvalidArgument Bucket POST must contain a field named 'key'. If it is specified, please check the order of the fields.keyA68024822D18802EqCwAGDupGKUViTrwXYrKHhDdOWJzq1oWpjz+q/yrWzVPLvrmty3JgZEVdHyrs/8NeagWNZQ409s="}

whats the reason for this? sorry to bug you I know this really isn't in the scope for this. Thanks for the great add on and all the help!

from django-s3direct.

aTylerRice avatar aTylerRice commented on June 29, 2024

Problem was that dictionaries aren't ordered in python you must use an ordered dictionary.

from django-s3direct.

amitassaraf avatar amitassaraf commented on June 29, 2024

Sure, you can call get_upload_params with 3 post params:

POST /s3direct/get_upload_params
type=video/quicktime
filename=filename.mov
dest=s3DirectDestinationFromSettings

Which returns all of the fields required to post directly to S3:

{  
  "policy":"generated-policy",
  "acl":"public-read",
  "signature":"JeEUf7TNFv5qOk3NmKAZaeIRZbk=",
  "form_action":"https://s3-eu-west-1.amazonaws.com/my-bucket",
  "key":"files/filename.mov",
  "Content-Type":"video/quicktime",
  "AWSAccessKeyId":"my-aws-key",
  "success_action_status":"201"
}

You can then post the file directly:

POST https://s3-eu-west-1.amazonaws.com/my-bucket
policy=generated-policy
acl=public-read
signature=JeEUf7TNFv5qOk3NmKAZaeIRZbk=
key=files/filename.mov
Content-Type=video/quicktime
AWSAccessKeyId=my-aws-key
success_action_status=201
file=binary

@bradleyg Can you update this to the latest version as it have changed since then? I am trying to use this as an API along with React JS frontend but I am not sure the requests I need to make. If you update it I'll submit a PR to the documentation adding how to use with React / Front end JS lib

from django-s3direct.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.