2

I use a Django and boto3 sdk

This is the current treatment methods.

1. The client sends the file to Django(EC2)
2. Save the file to Django(EC2)
3. Send a file stored on Django(EC2) to S3.

However, This is inefficient. So, I would like to do this

1. The client sends the file to Django(EC2)
2. The real-time transmission in the receiving file S3

I want not to store the EC2.... However, To transfer files to S3 , I need to check the file information in the previous EC2. I do not want to transfer files to S3 from the client.

It is to dynamically transferred to S3 in EC2.

How can I do this?

4 Answers4

2

There are several ways to allow the user to upload directly from their client browser to S3:

The following describes the process behind this:

Amazon S3 supports POST, which allows your users to upload content directly to Amazon S3. POST is designed to simplify uploads, reduce upload latency, and save you money on applications where users upload data to store in Amazon S3. http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingHTTPPOST.html

Some viable options that you can use/adapt:

  1. Direct to S3 File Uploads in Python
  2. How to generate a temporary url to upload file to Amazon S3 with boto library?
  3. How to upload directly to S3 using AWS Javascript SDK
Community
  • 1
  • 1
BestPractices
  • 12,738
  • 29
  • 96
  • 140
0

You can use django-storages to send files up to s3, Here are docs on just the S3 part http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html. Here is a video on it as well https://godjango.com/47-django-storages-and-amazons3/

Buddy Lindsey
  • 3,560
  • 6
  • 30
  • 42
  • 6
    django-storages requires routing through your server which ignores the premise of this question.... – Alvin Feb 28 '19 at 05:11
0

You can POST the file to S3 directly with aws-sdk.

  1. POST filetype and filesize to Django.
  2. Presign a s3-url with aws-sdk. (Allow the client to POST the file to a specific path on S3)
  3. POST the file direct from the Client to S3.

See the example below (but it's in js) https://github.com/bookingbricks/file-upload-example

Jonatan Lundqvist Medén
  • 2,750
  • 1
  • 17
  • 15
0

This looks promising -- https://github.com/Cadasta/django-buckets

django-buckets provides a Django storage system (S3Storage) to store files on Amazon S3. Besides the storage itself, the library comes with a custom model field (S3FileField) to reference files in Django and a form widget that handles uploading files to S3 using pre-signed URLs.

it's pretty late here, gonna try using it if anyone leaves a comment reminding me I'll follow-up to share my experience with it

Alvin
  • 2,533
  • 33
  • 45