- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想从 MimeType 获取扩展名。
例如:
video/mp4 ----> mp4
application/x-rar-compressed ----> rar
text/plain ----> txt
application/pdf ----> pdf
要在 Windows 或 Linux 上保存我的文件,我有这个方法可以让我从 URL 下载文件。所以,我只能在没有扩展名的情况下保存它(我不想要那样)。
这个方法让我只能得到 MimeType 而不是 extension。
public void downloadImage() {
String dirPath = "/home/MyPC/Downloaded";
String fileName = "My downloaded file";
URL fetchFile = new URL(IMAGE_URL);
byte[] fileAsArray = Resources.toByteArray(fetchFile);
//Getting the MimeType
String mimeType = URLConnection.guessContentTypeFromStream(new ByteArrayInputStream(fileAsArray));
System.out.println(mimeType);
File fileToWriteTo = new File(dirPath.concat("/" + fileName));
//Saving the file using Guava
Files.write(fileAsArray, fileToWriteTo);
}
如何使用 MimeType 编写带有扩展名的文件?
最佳答案
一般有两种方式:
第二种方法确实不好,所以我只提供它来完成。对于第一种方法,您可以使用此资源:https://www.freeformatter.com/mime-types-list.html
我会使用 HashMap<K,V>
- 键是 MimeType,值是扩展名(或类似的)。
关于java - 从 MimeType 获取扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48053127/
我正在使用 MediaRecorder API 在页面上录制一些媒体。在我的 MediaRecorder 初始化中,我没有指定内容类型,因为我不需要任何特别的内容。浏览器可以选择它想要的内容。 var
我有一个可以返回 text/html 或 application/pdf 内容的 servlet。显然,看起来 Internet Explorer (IE7) 没有正确处理应用程序/pdf。 例如。
我正在使用 C# 库 DotNetZip(Ionic.Zip 和 Ionic.Zlib)从目录生成电子书。目录如下所示: BookName | |___content/ | images/
我有一个带有二进制字段的文件模型 class File(models.Model): id = models.AutoField(primary_key=True) file = mo
覆盖模型保存方法时,有没有办法获取上传文件的内容类型?我试过这个: def save(self): print(self.file.content_type) super(Media,
我正在从 azure 读取文件。 mimetype 是 video/mp4 ,位于 response.headers["content-type"] 中。我找不到如何向文件添加 mimetypes,因
我想知道如果我运行这段代码会发生什么: MimeType Tester 我的内容将被解析为 XML 或 HTML?两个都?其他? 我还有一个 JS
我怎样才能从应用程序中获取 mimeType。 我正在开发一个基于 mimeType 过滤某些已安装应用程序的应用程序。 有人可以帮我解决这个问题吗? 非常感谢 最佳答案 mime 类型与 Activ
我需要获取项目对象的 MimeType: 我有什么:- 来自 EWS 的项目对象 (microsoft.exchange.webservices.data.Item) 我想要什么:- 该项目的 mim
我下载了一些文件,比如word、ppt、excel。但我不知道他们的 MIMETYPE 和后缀。有什么方法可以获取这些文件的 MIMETYPE? 最佳答案 如果您不知道后缀,则必须查看文件内容。通常,
如何使用 mimetypes 包中的 add_type() 函数添加新的 mimetype?我需要对 python 文件系统做些什么吗?如果我尝试类似这样的操作:add_type('text/new'
有人知道一种从字节数组中获取 mime 类型的方法吗?注意,我想在没有外部库的情况下做到这一点,只有 native java。 最佳答案 有一种方法可以使用 Java 7 来做到这一点,但它有点笨拙(
这只是一个用户上传一个文件。 最佳答案 UploadedFile.content_type 将返回上传时随文件一起发送的内容类型 header 。 如果您还需要在保存后检查文件,您可以使用 pytho
我正在尝试使用 Intent 打开一个 File,但 Android 没有打开适合该文件类型的应用程序。 使用以下代码,每个文件 - pdf、图像,所有内容 - 都使用音乐应用程序打开: Intent
从文件中使用 finfo 获取 mimetype $finfo = new finfo(FILEINFO_MIME); $type = $finfo->file($file); 从字符串中使用 fin
MIME::Types.type_for(filename) 我需要安装什么 gem,使用它需要什么文件? 最佳答案 gem install mime-types 和require 'mime/typ
我有两个节点应用程序在两个不同的端口上运行。 为了让 nginx 适本地路由请求,我有两个位置 block , # /etc/nginx/sites-available/my_site.com ser
如何在 xcode 中将 mimetype 转换为文件扩展名 例如我有这个代码 File Extension MIME Type aifc audio/x-aif
我正在考虑使用浏览器的 navigator.mimeTypes 数组作为第三级用户/浏览器标识符。例如,当我在 Chrome 上运行时... console.log(navigator.mimeTyp
我正在通过 MimeType 扫描目录。到目前为止,我的代码计算了目录中现有 MimiType 的总数: File dir = new File(dirPath); File[] files = di
我是一名优秀的程序员,十分优秀!