2

My project in .net core 2

I get base64string of file from web api, I Need this steps

  1. Check string is valid file ?
  2. Check file is image ? (optional)
  3. get file format
  4. get file size
  5. save file in directory

I write this steps in php, But for c# .net core 2 i could not find the right functions

Pooria Sadeghy
  • 373
  • 1
  • 5
  • 17
  • 1
    1. Check if all the characters are `A-Z`, `a-z`, `0-9`, + or `/`. 2. Decode base64 to get bytes and then use `System.Drawing.Common.Image` to try and load the image. If it fails, the image is invalid, else it's valid. 3. Use the loaded image from 2 to find out the format. 4. Length of bytes. 5. `System.IO.File.WriteAllBytes`. – ProgrammingLlama Aug 26 '18 at 06:24
  • for image your answer is perfect , but for file, how get format and size of file and save file ? – Pooria Sadeghy Aug 26 '18 at 06:42
  • That's a very complicated question. Not all files types have headers, etc. [This question](https://stackoverflow.com/questions/1654846/in-c-how-can-i-know-the-file-type-from-a-byte) touches on it. – ProgrammingLlama Aug 26 '18 at 08:58

0 Answers0