简体   繁体   English

将图像上传到S3存储桶并将URL存储在Django DB中

[英]Uploading Images to S3 Bucket and Storing the URL in Django DB

I have a react native application which uses Django as the backend. 我有一个反应本机应用程序,它使用Django作为后端。 REST APIs are used to send and retrieve data from the DB. REST API用于从数据库发送和检索数据。 Everything is smooth till the point where I have text information to be uploaded to DB which is easily handled by REST API. 一切都很顺利,直到我将文本信息上传到DB为止,REST API可以轻松处理这些信息。 How do I upload images to S3 from the react native application and store the URL in my DB. 如何从react native应用程序将图像上传到S3并将URL存储在我的数据库中。 Do I use an Image Field or is a regular CharField enough ? 我应该使用Image Field还是常规的CharField就足够了? Do I need to configure S3BOTO in my Django application ? 我需要在Django应用程序中配置S3BOTO吗?

You can use django-storages to setup the upload backend to use s3, then you just setup a ImageField 您可以使用django-storages设置上传后端以使用s3,然后只需设置一个ImageField

class MyModel(models.Model):
    ...
    image = models.ImageField(upload_to='my_image_folder')

The upload_to parameter will use an existing folder on your s3 setup, or create a new folder. upload_to参数将使用s3设置上的现有文件夹,或创建一个新文件夹。 Your image will be uploaded, and when you serialize your model, you will get the url for it. 您的图片将被上传,并且在您序列化模型时,将获得其URL。

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

相关问题 将文件上传到S3存储桶-Python Django - Uploading files to S3 bucket - Python Django AWS S3:图像正在上传到存储桶,但文件未显示在heroku Django中 - AWS S3: image is uploading to bucket but file is not showing in heroku Django Django在上传到Amazon S3存储桶之前更改图像名称 - Django changes image name before uploading to Amazon S3 bucket Flask 中的 Celery 任务,用于上传和调整图像大小并将其存储到 Amazon S3 - Celery task in Flask for uploading and resizing images and storing it to Amazon S3 使用 s3 和 django-storages 并上传图片 - using s3 with django-storages and uploading images Boto3 上传到 s3 存储桶 - Boto3 uploading to s3 bucket 使用Heroku上的Django将大文件上载到AWS S3 Bucket,没有30秒请求超时 - Uploading Large files to AWS S3 Bucket with Django on Heroku without 30s request timeout 从Django模型表单调整图像大小,然后再将其上传到Amazon S3存储桶 - Resize an image, from Django model form before uploading it to amazon s3 bucket 在Django应用程序中上传到非美国标准AWS S3存储桶时出错; 美标铲斗完美工作 - Error uploading to a non-US Standard AWS S3 Bucket in Django application; US Standard bucket works perfectly Django - AWS S3 存储桶 - 显示图像/css 但不显示 javascript/webfont 和文件上传 - Django - AWS S3 Bucket - Showing images/css but not javascript/webfont and file uploads
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM