0

I am storing the image file details in the database. Along with the path, I am also planning to store the byte array in case of accidental deletion of the uploaded folder. I would be using SQL express database as I want to use the app locally. As the size of SQL express is 10GB is it advisable to store a byte array of images in the database. Does the size of the byte array is same as the size of the image? As I am expecting the images to be of around 5-10MB.

using (var fileStream = new FileStream(filePath, FileMode.Create))
                    {
                        await postPatientInformationEntity.PatientPhoto.CopyToAsync(fileStream);
                        fileInformationEntity.Path = filePath;
                        fileInformationEntity.Name = postPatientInformationEntity.PatientPhoto.FileName;
                        fileInformationEntity.Type = postPatientInformationEntity.PatientPhoto.ContentType;

                    }
                    using (var ms = new MemoryStream())
                    {
                        await postPatientInformationEntity.PatientPhoto.CopyToAsync(ms);
                        var fileBytes = ms.ToArray();
                        fileInformationEntity.FileData = fileBytes;
                        // act on the Base64 data
                    }
Bilal Mehrban
  • 638
  • 6
  • 15
Ajinkya Gadgil
  • 117
  • 1
  • 8
  • 2
    Does this answer your question? [What are the pros and cons of storing files in a database?](https://stackoverflow.com/questions/2458739/what-are-the-pros-and-cons-of-storing-files-in-a-database) – Nino van der Mark Jan 20 '21 at 08:49
  • 1
    https://stackoverflow.com/questions/13420305/storing-files-in-sql-server – Mitch Wheat Jan 20 '21 at 08:53

1 Answers1

2

An alternative, and better method is to store the images outside of the database and store only a link to the image file. You only need a text field in your database table to store this information. The only problem to this approach is that you must synchronize the data in the link field with your file system. The possible solution is to store it in the file system, if the images need to be accessed from another server, tools like rsync can be used to move files from one server to other. this tools can be automated in order to sync the filesystems in constant intervals. The path of uploaded file is enough.