-1

I have a question about standard procedure of storing images in sql and process of this procedure. Quit over view of this: users uploading images from app and i need to save them.

My questions are : 1. how do i store them? I was able to find some post where people suggested using Binary and some suggested image. I believe image will no longer be available in later sql. 2. how do i grab physical file from api call. I currently can see my file name and all the details. My question is how do i actually grab physical file and put in binary array. I was only able to fin solutions where people use physical paths to theirs files. 3. how do I retrieve file from sql. I guess this will depend on how i will store it.

public IHttpActionResult UploadBridgeImage()
        {
            var httpRequest = HttpContext.Current.Request;
            if (httpRequest.Files.Count > 1)
            {

            }

            try
            {
                return Ok();
            }
            catch (Exception)
            {
                return InternalServerError();
            }
        }

Thank you for your help. Any guidance are appreciated or even a helpful link where i can learn it from.

kkdeveloper7
  • 497
  • 2
  • 11
  • 25

2 Answers2

0

If you are using SQL Server - then a suggestion is to use FileStream storage.

The advantage of this is that you still get all the transactional support that comes with SQL Server. It also backs up the data along with everything else.

https://msdn.microsoft.com/en-us/library/gg471497.aspx

Examples here:

https://msdn.microsoft.com/en-us/library/cc716724(v=vs.110).aspx

William Xifaras
  • 5,212
  • 2
  • 19
  • 21
-1
  1. Store the images as a binary type in your database. Depending on your database, you might need blob, varbinary, etc. You can also just save the file to a standard, accessible location and just store the path to that filepath, but for most cases you'll just want the file in your database itself. Your C# model will have a byte[] member to map to that column if you go the binary route.
  2. You'll need to make your web client upload the file contents through the request body in a POST request. The binary image data will be available as HttpContext.Request.Current.InputStream. Deal with that like any other binary stream to save it to your database.
  3. Can't answer this without knowing how you're interacting with your database. If you are using Entity Framework or Linq to SQL, you can do something like this.
Community
  • 1
  • 1
S.C.
  • 1,152
  • 8
  • 13
  • Another option can be to work with Base64 strings...please explain how the user submits file so I can help you with grabbing the file? You have an application that makes an API call? – Andreas Pilavakis Jun 13 '16 at 19:17