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 类型


基础教程推荐
- 验证是否调用了所有 getter 方法 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01