Any way to guess the mime type on Delphi XE2?

前端 未结 4 866
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-08 13:09

I need to guess the mime type with the purpose of fill the \"Content-Type\" header for some file uploads.

I fail to found a solution for it.

I wish to call somet

4条回答
  •  执念已碎
    2021-02-08 13:25

    Try using the FindMimeFromData Function.

    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.

    from 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;
    

    Also this article to see hot it works MIME Type Detection in Internet Explorer

提交回复
热议问题