0

I have setup filestream on my mssql server, and it works pretty well thus far. Currently, I have one entity in my database, that I have added manually.

When I added my file, it was automatically converted to a byte[], which Similarly appears as a byte[] when I get it through my .NET Core application (surprise).

Optimally, I would like to know, how I can decode this byte array into the original file? I have read several places, that I need to provide the original extension of the file in order to do that.

However, I have not added such a column in my database - I could easily add such a column, but it seems odd to me, if it isn't possible to pass it back to its original format without providing additional parameters.

Therefore, is there a way, in which I can convert the byte array back to its original file so that the user easily can download it, without having to do some sort of comprehensive conversion? I would happily like to know, if one of you can point me in a direction here.

Jeppe Christensen
  • 1,680
  • 2
  • 21
  • 50

1 Answers1

0

A filestream column contains the file's contents, not its external metadata, like the original filename, extension, directory location and access control list. If you write the byte[] to disk with, eg, File.WriteAllBytes(string,byte[]) it will be a usable file.

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
  • So what you suggest here, is that I use `WriteAllBytes` to my filestream column (Is that best practice, or would i add a column to support the original filename)? Or do you suggest, that I discard filestream and make the database hold a pointer to the file? – Jeppe Christensen Mar 13 '20 at 23:57
  • The filestream _is_ a pointer to the file. But you need to store the file name in a separate column. – David Browne - Microsoft Mar 14 '20 at 00:05