GetMimeTypeByContent() public method

Find the Mime Content Type of a stream from its content.
public GetMimeTypeByContent ( Stream data ) : MimeType
data Stream are the first bytes of data of the content to analyze. /// Depending on the length of provided data, all known MimeTypes are /// checked. If the length of provided data is greater or egals to /// the value returned by {@link #getMinLength()}, then all known /// MimeTypes are checked, otherwise only the MimeTypes that could be /// analyzed with the length of provided data are analyzed. /// ///
return MimeType
示例#1
0
        public static string GetMimeTypeString(string filePath)
        {
            var mimeTypes = new MimeTypes();

            MimeType mimeType;

            using (var fileStream = new FileStream(filePath, FileMode.Open))
            {
                mimeType = mimeTypes.GetMimeTypeByContent(fileStream);
            }



            if (mimeType == null)
            {
                mimeType = mimeTypes.GetMimeType(filePath);
            }

            if (mimeType == null)
            {
                return(null);
            }

            return(mimeType.Name);
        }
		public static string GetMimeTypeString(string filePath)
		{
			var mimeTypes = new MimeTypes();

			MimeType mimeType; 

			using (var fileStream = new FileStream(filePath, FileMode.Open))
			{
				mimeType = mimeTypes.GetMimeTypeByContent(fileStream);
			}

			

			if (mimeType == null)
			{
				mimeType = mimeTypes.GetMimeType(filePath);
			}

			if (mimeType == null)
			{
				return null;
			}

			return mimeType.Name;
		}