从Base64编码的字符串中检索MIME类型 [英] Retrieve MIME type from Base64 encoded String

查看:477
本文介绍了从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)?

推荐答案

通常,基本的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解码,然后执行诸如检查其

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类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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