Django Storages [file upload to AWS S3]

Viewed 1398

I am using django storages library for upload my files to s3. I want to understand how this file uploads works , does the file uploads to s3 folder directly or it uploads to my server and then goes to s3?

How does the file upload works in django storages.

If I upload multiple files , will they use bandwidth of my server of will they be directly uploaded to s3 and will not slow the speed of my server.

Thank you

1 Answers

Django-storage uses boto3 for uploads, as can be seen in its source code here:

obj.upload_fileobj(content, ExtraArgs=params)

which is the upload_fileobj method in boto3:

Upload a file-like object to this bucket. The file-like object must be in binary mode. This is a managed transfer which will perform a multipart upload in multiple threads if necessary.

Looking at the save method in Django-storage it future explains:

Save new content to the file specified by name. The content should be a proper File object or any Python file-like object, ready to be read from the beginning.

So to answer your question, the file must go through your server first so that you can create file-like object for it. It does not have to be necessarily stored on a hard drive, but the file data can be in memory. Also I think it also does not have to be fully stored, it should be possible to steam it as its being uploaded to your app, but I'm not certain if this works in django.

To sum up, all uploaded files must go through your server taking it processing power and bandwidth.

Related