0

In our business application we handle images and videos. I have created the Entity Framework model based on this answer:

https://stackoverflow.com/a/6241232/3850405

I know this will result in varbinary(MAX) which has a limit to around 2 GB since EF does not support FILESTREAM out of the box.

https://stackoverflow.com/a/5723825/3850405

What I can't find however is what the recommended maximum file size is? I know that this could fall under opinion based but I hope that the given context allows it. For images I was thinking around 5 mb and videos 200 mb and only fetch them when the user want's to see them (Name will be showed in Front End).

Is this a good solution or should I rethink this all together? Would it be beneficial to implement FILESTREAM even though it is not supported by default?

Current model:

public class Media
{
    [Key]
    public int Id { get; set; }

    public DateTime Created { get; set; }

    public DateTime Updated { get; set; }

    public virtual ICollection<Image> Images { get; set; }

    public virtual ICollection<Video> Videos { get; set; }
}

public class Image
{
    [Key]
    public int Id { get; set; }

    public DateTime Created { get; set; }

    public DateTime Updated { get; set; }

    public string Name { get; set; }

    public virtual byte[] Image { get; set; }

    public int MediaId { get; set; }

    public virtual Media Media { get; set; }
}

public class Video
{
    [Key]
    public int Id { get; set; }

    public DateTime Created { get; set; }

    public DateTime Updated { get; set; }

    public string Name { get; set; }

    public virtual byte[] Video { get; set; }

    public int MediaId { get; set; }

    public virtual Media Media { get; set; }
}
Ogglas
  • 62,132
  • 37
  • 328
  • 418
  • The entire .net framework has a maximum memory size of 2GB, so if you are doing anything that even approaches 2GB in size then you will have to devise a buffering system to chunkify your data into smaller sections, as such it is the chunks you would be saving into your database not files and as there is no limit to how many chunks a file can be split into then there is no limit on file size – MikeT Jun 14 '17 at 09:54
  • Chunk size in normally targeted at Memory Page size which is 4KB – MikeT Jun 14 '17 at 10:06
  • 1
    *EF does not support FILESTREAM out of the box* No, but if a table has a filestream column, EF will read and write to it, just not in the optimized streaming fashion through a `SqlFileStream` object. – Gert Arnold Jun 14 '17 at 10:17
  • Dont store images and videos in the database, but in the filesystem. Maintain the path to these files in the database. – Jehof Jun 14 '17 at 10:21
  • @Jehof I don't agree. They shouldn't be stored in regular table columns, but in filestream columns. Storing links to an external file system is a disaster. – Gert Arnold Jun 14 '17 at 10:34

1 Answers1

0

There isn't really any objective way to decide what your maximum should be.

SQL only provisions what is needed by your data anyway so if you have used varbinary(max) for your column data type and you only have a 200MB video file going in there, it doesn't matter that the field has a capacity of 2GB because its only using 200MB.

With that in mind, I'd suggest using varbinary(max) anyway unless you know for a fact exactly how big every file is going to be. That way you can be sure there'll be space for it and you won't have your data being truncated to fit.

Ortund
  • 8,095
  • 18
  • 71
  • 139