我已经写了一个下载处理程序,它运行良好。但问题是它正在下载名为“download”的文件,下一次它变成“download(1)”等等。这样地:
我想下载它的真实名字。
这是我的下载处理程序代码:
from google.appengine.ext.webapp import blobstore_handlers
import functions
class DownloadHandler(blobstore_handlers.BlobstoreDownloadHandler):
def get(self):
filename = self.request.get('file_name')
file_object = functions.getFileList(filename)
self.send_blob(file_object.blob)
这是函数getFileList()的代码:
def getFileList(file_name):
currentUser = getCurrentUser()
directoryList = getDirectoryList()
path = getFilePath(file_name, directoryList)
fileID = currentUser.key.id() + path
fileKey = ndb.Key(File, fileID)
return fileKey.get()
此函数涉及的流程是:
-getCurrentUser():返回登录用户的当前用户id。
-getDirectoryList():返回一个目录对象,其中有一个目录列表。
-getFilePath():这将返回文件路径userId+directoryPath+filename。
示例:185804764220139124118/新文档2019-03-07 03.23.46_1.jpg
这是对HTML文件中main.py的调用:
<td class="table_data icon_row">
<a href="/download?file_name={{ file }}" class="table_link"><span class="material-icons button">file_download</span></a>
</td>
而main.py作为
app = webapp2.WSGIApplication(
[
('/', MainPage),
('/upload', UploadHandler),
('/download', DownloadHandler)
], debug=True)
上面给出了下载处理程序的代码。
如何下载带有实际名称的文件。
注意:数据存储上的文件名是实际的,但仅下载时存在一些问题。