[英]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.