从Dropbox下载Django GET请求

时间:2018-11-10 02:05:46

标签: django get httprequest dropbox

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)

当我尝试此操作时,它只会为我提供文件的元数据,而不是文件本身。有没有办法让它返回文件?谢谢!

1 个答案:

答案 0 :(得分:0)

您可以按照https://github.com/dropbox/dropbox-sdk-python/blob/master/example/back-up-and-restore/backup-and-restore-example.py

上的说明调用files_download_to_file。
# 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)