Good day.
There is a database in which user accounts are stored. Two binary files are associated with each user. The first file takes about 30KB, the second takes about 300KB. Over time, the number of users can be in the hundreds of thousands.
The first option is to store this data in a database. The Data field in the table will be of the varbinary (MAX) type:
public ActionResult GetWorld() { var world = db.GetWorld(...); return File(world.Data, "application/octet-stream"); } public ActionResult SaveWorld(HttpPostedFileBase worldData) { var world = db.GetWorld(...); world.Data = new byte[worldData.ContentLength]; worldData.InputStream.Read(world.Data, 0, worldData.ContentLength); }
The second option is to store this data as separate files:
public ActionResult GetWorld() { var world = db.GetWorld(...); string pathToWorldData = Server.MapPath( string.Format("~/App_Data/Worlds/{0}.dat", world.Id)); return File(pathToWorldData, "application/octet-stream"); } public ActionResult SaveWorld(HttpPostedFileBase worldData) { var world = db.GetWorld(...); string pathToWorldData = Server.MapPath( string.Format("~/App_Data/Worlds/{0}.dat", world.Id)); worldData.SaveAs(pathToWorldData); }
There is another option - varbinary (MAX) and FILESTREAM, but how is it essentially different from the second? Only there will be a lot of fuss in the code.