Esempio n. 1
0
        public async Task <string> WriteFileByte(byte[] file)
        {
            string fileName;
            var    folder = "images/";

            try
            {
                var extension = WriterHelper.GetFileExtension(file);
                var stream    = new MemoryStream(file);
                fileName = Guid.NewGuid().ToString() + extension;
                //IFormFile ImageFile = new FormFile(stream, 0, file.Length, "ImageFile", fileName);

                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images", fileName);

                if (extension == ".pdf" ||
                    extension == ".doc" ||
                    extension == ".docx")
                {
                    path   = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\documents", fileName);
                    folder = "documents/";
                }

                using (var bits = new FileStream(path, FileMode.Create))
                {
                    await bits.WriteAsync(file, 0, file.Length);
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            return(fileName);
            //return ApiRoutes.Domain + folder + fileName;
        }
Esempio n. 2
0
        private bool CheckIfDocumentFile(IFormFile file)
        {
            byte[] fileBytes;
            using (var ms = new MemoryStream())
            {
                file.CopyTo(ms);
                fileBytes = ms.ToArray();
            }

            return(WriterHelper.GetDocumentFormat(fileBytes) != WriterHelper.DocumentFormat.unknown);
        }
Esempio n. 3
0
 private bool CheckIfDocumentByteFile(byte[] document)
 {
     return(WriterHelper.GetDocumentFormat(document) != WriterHelper.DocumentFormat.unknown);
 }
Esempio n. 4
0
 private bool CheckIfImageByteFile(byte[] file)
 {
     return(WriterHelper.GetImageFormat(file) != WriterHelper.ImageFormat.unknown);
 }