Django-Google Drive API如何使用Django存储和检索文件



我需要通过使用Django构建的web应用程序在google drive中上传和下载图像文件。我已经探索过使用Django Google Drive Storage API,它似乎可以在保存文件时工作。但我不知道这些文件保存在哪里,也不知道如何读取这些文件。如果有人有使用Django谷歌驱动器API的经验,或者有在谷歌驱动器中存储文件的建议,那么目前将非常有帮助。

谢谢。

如果您正在使用模型上传图像文件,则如下所示:

class Imageupload(models.Model):
imagefile= models.ImageField(upload_to='img',blank=True,storage=gd_storage)

views.py文件看起来像:

lst=Imageupload.objects.all()
url_for_first_imagefile=lst[0].imagefile.url #used to display or download the image in template

然后您可以使用imagefile.url属性直接访问它们。

最新更新