iOS文件上传-原始文件名 [英] iOS file upload - original filename

查看:210
本文介绍了iOS文件上传-原始文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的HTML文件上传代码段,该代码段也适用于iOS.但是我的问题是上载文件的文件名将始终是"image.jpeg".有没有办法获取原始文件名-即"IMG_0001.jpg"?主要问题是,如果我选择了2个文件,则它们的名称都为"image.jpeg",而不是其唯一名称.

I have a simple HTML file upload snippet that works under iOS as well. However my problem is that the filename of the uploaded file will always be 'image.jpeg'. Is there a way to get the original filename - i.e. 'IMG_0001.jpg' instead? The major issue is that if I have 2 files selected they both have the name of 'image.jpeg' as opposed to their unique names.

推荐答案

iOS上的Safari始终将上传文件的名称命名为image.jpeg,大概是出于安全/隐私目的.您需要为文件生成自己的名称,通常对于上传的文件来说这是一个好主意:您永远都不想太信任客户端.

Safari on iOS will always make the name of the uploaded file image.jpeg, presumably for security/privacy purposes. You need to generate your own name for the files, which is a good idea in general for uploaded files: you never want to trust the client too much.

如果您不仅针对iOS上的Safari,还需要处理这种情况,因为人们上载具有相同名称但最初位于不同目录的多个文件是合理的.

If you are targeting more than just Safari on iOS, you will still need to handle this case because it is reasonable that people might upload multiple files with the same name, but originally located in different directories.

这篇关于iOS文件上传-原始文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆