Can Hive in Flutter Store BigData(some GB files)

6.3k Views Asked by At

I was thinking if I store a video or a movie and open that box will that video will be stored in my RAM or else it just load from ROM. I am a bit confused: Can anyone explain this to me?

2

There are 2 best solutions below

1
On

I think you have misunderstood the concept of Database.

  • Any Database solution is to only store pure informational organized data. Not to store large files such as media, documents, or images.

  • On the contrary, storage need not be organized, all files can exist in one folder.

So, any database solution you use, always store Data Types. In this case you can have a Data Model, which is also an essential thing in using a Database.

@HiveType(typeId: 0)
class Movie extends HiveObject {

  @HiveField(0)
  String name;

  @HiveField(1)
  int path;
}

Since Hive supports Dart objects, you don't have to convert toJson or any such for string the Data.

So when you have the file fetched from Storag, you can get the path using path_provider or from the File itself, and then Create a Object

File file = await // get the movie file using any means

final path = file.path

var box = await Hive.openBox('Movies');

var m = Movie()
  ..name = 'Batman Begins'
  ..path = path ;
box.add(m);

m.save();

Hope this clears your doubt.

1
On

Copy/save your video/media files in the Local File Storage and save file path in Hive Box.

Whenever you need get path from hive then get the file from local storage using that path.