flask中的secure_filename方法获取不到中文文件名
来源:互联网 发布:caffe softmax层 编辑:程序博客网 时间:2024/06/06 12:56
碰到以下问题:
将中文文件名传给 secure_filename 方法时所有的中文名都会被过滤掉,只剩下文件后缀名。
原因:werkzeug库的secure_filename方法中,中文被ignore或者压制导致数据缺失
解决方法:
1,要么更换或弃用中文文件名
2,视情况修改secure_filename方法的代码
def secure_filename(filename): r"""Pass it a filename and it will return a secure version of it. This filename can then safely be stored on a regular file system and passed to :func:`os.path.join`. The filename returned is an ASCII only string for maximum portability. On windows systems the function also makes sure that the file is not named after one of the special device files. >>> secure_filename("My cool movie.mov") 'My_cool_movie.mov' >>> secure_filename("../../../etc/passwd") 'etc_passwd' >>> secure_filename(u'i contain cool \xfcml\xe4uts.txt') 'i_contain_cool_umlauts.txt' The function might return an empty filename. It's your responsibility to ensure that the filename is unique and that you generate random filename if the function returned an empty one. .. versionadded:: 0.5 :param filename: the filename to secure """ if isinstance(filename, text_type): from unicodedata import normalize filename = normalize('NFKD', filename).encode('ascii', 'ignore') if not PY2: filename = filename.decode('ascii') for sep in os.path.sep, os.path.altsep: if sep: filename = filename.replace(sep, ' ') filename = str(_filename_ascii_strip_re.sub('', '_'.join( filename.split()))).strip('._') # on nt a couple of special files are present in each folder. We # have to ensure that the target file is not such a filename. In # this case we prepend an underline if os.name == 'nt' and filename and \ filename.split('.')[0].upper() in _windows_device_files: filename = '_' + filename return filename
0 0
- flask中的secure_filename方法获取不到中文文件名
- 关于struts2中文件上传获取不到文件名的问题
- 获取url中的文件名
- 获取地址中的文件名
- 获取不到方法的注解
- c# 获取路径中的文件名
- C++获取路径中的文件名
- vc++获取路径中的文件名
- java_获取文件中的文件名
- python 获取目录中的文件名
- Python获取路径中的文件名
- JS获取文件名的方法
- JS获取文件名的方法
- android中intent带Uri传输时中文的乱码、android 获取文件名乱码处理方法
- FTP获取中文文件名乱码问题
- Python2获取中文文件名的编码问题
- 获取文件夹中的文件夹中的文件名
- hadoop中的Mapper实现类中map方法获取文件名时报错
- Java 中数组的冒泡排序 和 直接选择排序
- 程序员自我修练-提高写代码的能力
- 利用rsync同步备份文件
- 正则表达式语法
- Hibernate 查询 Projections 类使用 (一)
- flask中的secure_filename方法获取不到中文文件名
- [HDU1512]Monkey King(可并堆)
- WordPress中获取页面链接和标题的相关PHP函数用法解析
- The tslib functionality test failed问题解决方案
- java-类名.静态方法。类的构造没执行。
- 386. Lexicographical Numbers 难度:medium
- 散列
- netstat参数分析
- JDBC获取记录总数