2

I'm trying to use GUN to create a File sharing platform. I read the tutorial and API but I couldn't find a general way to upload/download a file.

I hear that there is a limitation of 5Mb of localStorage in GUN, if I want to upload a large file, I have to slice it then storage it into GUN. But right now I can't find a way to storage file into GUN.

I read the question from Retric and I know how to store the image into GUN, but can I store the other type of Files such as .zip or .doc File? Is there a general API for file storage?

jerryZhang
  • 51
  • 3

2 Answers2

3

I wrote a quick little app in 35 lines of HTML to demonstrates file sharing for images, videos, sound, etc.

https://github.com/amark/gun/blob/master/examples/basic/upload.html

I've sent 20MB files thru it, tho yeah, I'm sure there is a better way of splitting it up into 2MB chunks - that is currently not automatic, you'd have to code it.

We'll have a feature in the future that will automatically split up video files. Do you want to help with this?

I think on the download side, all you have to do is make sure you have the whole file (stitch it back together if you do write a splitter upper), and add it to some <a href=" target. Actually, I'm not sure exactly how, but I know browsers support download file attributes for a few years now, where you can create a download link even of a in-memory file... but you'll have to search online for how. Then please write a tutorial and share it with the community!!

marknadal
  • 7,534
  • 4
  • 25
  • 22
2

I would recommend using IPFS for file storage and GUN to store the links to those files. GUN isn't meant for file storage I believe, primarily user/graph data. Thus the 5 MB limitation.

GiraffeKey
  • 23
  • 3
  • The storage limitations is imposed by the client browser , not by gundb. Gun DB is a database with syncing feature among connected peers. You can use it offline without any peer like a regular storage too if you want. To get around the limitation, you can use Amazon S3 and specify the credential in the gun config when initialising. So, the S3 can be the persistent storage. You can set up relay server which you can setup yourself ready to deploy, available in the GunDB Docs. The relay peer will also cache the data and of course the other connected peers will have the data too. – John Yepthomi Oct 06 '22 at 03:49