所以我有这个代码可以下载PNG或TIFF的图像:
you have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1.
And ones more: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'lentele'.
此代码与PNG文件完美配合,但是当我尝试下载TIFF文件时出现以下错误:
image = Image.open(design.design.path)
format = image.format
extension = str(format)
response = HttpResponse(mimetype='image/' + extension.lower())
response['Content-Disposition'] = 'attachment; filename=%s' % file_name
image.save(response, format)
return response
为什么会发生这种情况,我该如何解决?
答案 0 :(得分:1)
在我看来,这是一个与文件格式无关的文件名错误。如果重命名该文件会发生什么?
您还可以通过编码器运行文件名,并忽略所有非utf8字符。例如:
>>> u'aあä'.encode('ascii', 'ignore')
'a'