简体   繁体   English

Django:使用Boto3将视频文件上传器上传到S3存储桶的问题

[英]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. 我想使用Boto3将视频文件上传到AWS S3存储桶。 I've already created a bucket named 'django-test' and given the required permissions. 我已经创建了一个名为“ django-test”的存储桶,并具有所需的权限。 I am using Django and working on Windows 10 machine. 我正在使用Django并在Windows 10计算机上工作。

I've created a function called store_in_s3 in views.py file in my Django app. 我在Django应用程序的views.py文件中创建了一个名为store_in_s3的函数。

The expected file size is lower than 200mbs. 预期的文件大小小于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' 此时,我收到以下错误: FileNotFoundError: [WinError 2] The system cannot find the file specified: 'test.mov'

But test.mov is the file I've uploaded using HTML form. 但是test.mov是我使用HTML表单上传的文件。

My code in HTML form is below: 我的HTML形式的代码如下:

<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. 附加信息:在此开发过程中,我成功地一次上传了视频文件,但是在S3上,它的大小非常小,只有28字节。 That's why I restarted building the uploader. 这就是为什么我重新开始构建上传器的原因。

在此处输入图片说明

I'll be greateful for any help. 我将不胜感激。 Please feel free if you need any more information on the question. 如果您需要有关此问题的更多信息,请随时。 Thank you. 谢谢。

As you mentioned the file size is greater than 2 MB, its getting stored in the temp location by Django. 正如您提到的,文件大小大于2 MB,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, ie file.temporary_file_path() 因此,通过传递临时位置路径(在这种情况下,即file.temporary_file_path()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM