我有一些文件存储在 OpenStack Swift(或任何其他存储系统)上。我的 django 应用程序提供了基于浏览器的 GUI 供用户从 Swift 后端下载这些文件:
(1) Each file will have a URL such as: http://domain.com/files/file1
(2) User could use browser or any other client program based on HTTP to download files.
我已经测试了静态文件下载为:
def download(request):
try:
#TODO
file_name = 'E:/sample.docx'
fsock = open(file_name,"r")
mime_type_guess = mimetypes.guess_type(file_name)
if mime_type_guess is not None:
response = HttpResponse(fsock, mimetype=mime_type_guess[0])
response['Content-Length'] = os.path.getsize(file_name)
response['Content-Disposition'] = 'attachment; filename=' + file_name
except IOError:
response = HttpResponseNotFound()
return response
我的问题是:
(1) 我可以从下载视图下载文件,但下载的文件大小始终为 1k。这里有什么问题?
(2) 我仍然不知道如何提供存储在其他对象存储后端(如 OpenStack Swift)上的动态文件下载?