Django GET请求从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)

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

您可以调用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)

最新更新