gpt4 book ai didi

delphi - 有什么方法可以猜测 Delphi XE2 上的 mime 类型吗?

转载 作者:行者123 更新时间:2023-12-03 14:40:48 25 4
gpt4 key购买 nike

我需要猜测 mime 类型,以便填充某些文件上传的“Content-Type” header 。

我没能找到解决方案。

我希望调用类似:GetMimeType('C:File.jpg') 并返回image/jpg

最好是多平台(适用于 win/osx),但如果仅适用于 Windows 就足够了。

最佳答案

尝试使用FindMimeFromData功能。

FindMimeFromData contains hard-coded tests for (currently 26) separate MIME types (see Known MIME Types). This means that if a given buffer contains data in the format of one of these MIME types, a test exists in FindMimeFromData that is designed (by scanning through the buffer contents) to recognize the corresponding MIME type.

来自 urlmon.pas

function FindMimeFromData(
pBC: IBindCtx; // bind context - can be nil
pwzUrl: LPCWSTR; // url - can be nil
pBuffer: Pointer; // buffer with data to sniff - can be nil (pwzUrl must be valid)
cbSize: DWORD; // size of buffer
pwzMimeProposed: LPCWSTR; // proposed mime if - can be nil
dwMimeFlags: DWORD; // will be defined
out ppwzMimeOut: LPWSTR; // the suggested mime
dwReserved: DWORD // must be 0
): HResult; stdcall;

还有这篇文章看看热它的作品MIME Type Detection in Internet Explorer

关于delphi - 有什么方法可以猜测 Delphi XE2 上的 mime 类型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9856265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com