I have a WCF REST Service with the following OperationContract that saves files on the disk:
[OperationContract]
[WebInvoke(UriTemplate = "FileSave", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
ResponseHandler FileSave(string fileName, string fileContent);
Files are sent through javascript - using HTML File API => binary data => base-64 encoded ASCII string (=fileContent is recieved in the operation contract)
I want to check the file type before saving the file on the disk.
I am aware of Checking MIME Type from a base64 string on the Code Review Stack Exchange but I am not sure if it is the best way to go. Also, I have tested uploading several .txt files and each one has different first 5 chars.
I am looking for a code snippet that would include checking for several common file types.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…