簡體   English   中英

Django - Google Drive API 如何使用 Django 存儲和檢索文件

[英]Django - Google Drive API how to store and retrieve file using Django

我需要通過使用 Django 構建的 web 應用程序在谷歌驅動器中上傳和下載圖像文件。 我已經探索過使用 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 屬性直接訪問它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM