【问题标题】:Django GET request download from Dropbox从 Dropbox 下载 Django GET 请求
【发布时间】:2018-11-10 02:05:45
【问题描述】:
class FileDropboxDownloadView(LoginRequiredMixin, View):
    login_url = global_login_url

    def get(self, request, pk):
        # return self.head(self)

        # use the path to find the filename
        db_query_file = self.request.path
        # remove the trailing slash
        db_query_file = db_query_file[:-1]
        # regular expressions to remove the beginning
        db_query_file = re.sub('^(/)[\w]+(/)[\w]+', '', db_query_file)

        dbx = dropbox.Dropbox(dropbox_token)
        return dbx.files_download(db_query_file, rev=None)

当我尝试这个时,它只会给我文件的元数据,而不是文件本身。有没有办法让它返回文件?谢谢!

【问题讨论】:

    标签: django get httprequest dropbox


    【解决方案1】:

    您可以调用 files_download_to_file 指出:https://github.com/dropbox/dropbox-sdk-python/blob/master/example/back-up-and-restore/backup-and-restore-example.py

    # Restore the local and Dropbox files to a certain revision
    def restore(rev=None):
        # Restore the file on Dropbox to a certain revision
        print("Restoring " + BACKUPPATH + " to revision " + rev + " on Dropbox...")
        dbx.files_restore(BACKUPPATH, rev)
    
        # Download the specific revision of the file at BACKUPPATH to LOCALFILE
        print("Downloading current " + BACKUPPATH + " from Dropbox, overwriting " + LOCALFILE + "...")
    dbx.files_download_to_file(LOCALFILE, BACKUPPATH, rev)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-30
      • 2012-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 2021-09-12
      相关资源
      最近更新 更多