Retrieve MIME type from Base64 encoded String(从 Base64 编码的字符串中检索 MIME 类型)
问题描述
假设一个用 Base64 字符串编码并提供给我的文件(例如 myfile.jpeg).我无法知道文件类型是什么.我想将字符串解码为文件(本例中为图像).我如何知道文件的类型(例如 jpeg)?
Let' say a file (e.g. myfile.jpeg) encoded in Base64 String and given to me. There is no way I know what the file type was. I'd like to decode the string into a file (an image in this example). How do I know the type of the file (e.g jpeg)?
推荐答案
一般来说,base 64 编码的字符串绝对可以包含任何数据,因此无法知道它的文件类型.
In general, a base 64-encoded string could contain absolutely any data, so there is no way to know its file type.
要确定它是否是 JPEG 图像的实例,您需要对其进行 base64 解码,然后执行诸如检查其 幻数,这有助于告诉您文件不是.您仍然需要做更多的工作来确定它是否是有效的 JPEG 图像.
To determine if it is an instance of a JPEG image, you'd need to base64-decode it, and then do something like checking its magic number, which is useful in telling you what the file isn't. You'd still need to do more work to determine if it is a valid JPEG image.
这篇关于从 Base64 编码的字符串中检索 MIME 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 Base64 编码的字符串中检索 MIME 类型
基础教程推荐
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
