下载时用浏览器取代的特殊字符?

时间:2016-08-03 14:22:11

标签: python django

我的django view.py:

def get(self, request, *args, **kwargs):
    try:
        self.object = self.get_object()
        file_path = settings.MEDIA_ROOT+self.object.file.name
        chunk_size = 8192
        response = StreamingHttpResponse(FileWrapper(open(file_path), chunk_size),
                content_type=mimetypes.guess_type(file_path)[0])
        response['Content-Length'] = os.stat(file_path).st_size
        response['Content-Disposition'] = 'attachment; filename="%s"' % smart_str(os.path.basename( file_path ))
        print 'response:', response
        return response

响应(来自日志文件):

[Wed Aug 03 14:16:54 2016] [error] response: Content-Length: 4194486\r
[Wed Aug 03 14:16:54 2016] [error] Content-Type: image/x-ms-bmp\r
[Wed Aug 03 14:16:54 2016] [error] Content-Disposition: attachment; filename="TestFileName`~@#$%^&*()-_+={}[]|:;<>,.? test   '.bmp

但是文件名中的一些字符似乎在下载时已被替换。

enter image description here

这是浏览器的行为?欢迎任何评论。感谢

0 个答案:

没有答案