disp_name
disp_name

Reputation: 1488

Django: Issue with a Video file uploader to S3 bucket using Boto3

I want to upload a video file to AWS S3 bucket using Boto3. I've already created a bucket named 'django-test' and given the required permissions. I am using Django and working on Windows 10 machine.

I've created a function called store_in_s3 in views.py file in my Django app.

The expected file size is lower than 200mbs. I am a bit confused with the several approaches I've tried. Below is the existing code

def store_in_s3(request):
        transfer = S3Transfer(boto3.client(
            's3',
            region_name = settings.AWS_S3_REGION_NAME,
            aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
            aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY
            ))
        client = boto3.client('s3')
        bucket = "django-test"
        file = request.FILES["file"]
        filename = file.name
        transfer.upload_file(filename, bucket, "test.mov")

At this point, I am getting the following error: FileNotFoundError: [WinError 2] The system cannot find the file specified: 'test.mov'

But test.mov is the file I've uploaded using HTML form.

My code in HTML form is below:

<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.file }}
<button type="submit">Submit</button>
</form>

Additional Information: I was successful at uploading the video file at one point in this development process but on S3 its size was ridiculously small - only 28 Bytes. That's why I restarted building the uploader.

enter image description here

I'll be greateful for any help. Please feel free if you need any more information on the question. Thank you.

Upvotes: 0

Views: 468

Answers (1)

Rashmit
Rashmit

Reputation: 51

As you mentioned the file size is greater than 2 MB, its getting stored in the temp location by Django. From the error message, it seems the filename can't be found. So, try it by passing the temp location path, in this case, i.e. file.temporary_file_path()

Upvotes: 1

Related Questions