0

I'm working on MVP of a post scheduling web app. I want to store files to be posted on local storage because of the storage costs on the server but I couldn't find any structure to store large files on local with JS.

How can I store image/video files locally on browser with JS?

I tried LocalStorage and FileSystem APIs but they aren't solving my problem. I want to read the file from local at the scheduled time.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
kaan.py
  • 27
  • 1
  • 3
  • 1
    To store data locally with JavaScript, you use LocalStorage or SessionStorage. They use a key/value type structure. I don't think it's the most suitable solution in your case, are you sure there isn't another way? – Dvalin99 Aug 16 '23 at 14:41
  • I've used LocalStorage to store base64 of the image but there is no enough space for lots of images. I mean LocalStorage is 2mb maximum but my image files are at least 1mb. – kaan.py Aug 16 '23 at 21:34
  • And where are those images coming _from_? – CBroe Aug 17 '23 at 06:16
  • can you not instead rely on browser caching? – Emre Bener Aug 17 '23 at 06:25
  • @CBroe coming from the user – kaan.py Aug 17 '23 at 10:24
  • 1
    _"I want to read the file from local at the scheduled time."_ - you can not read a file from the local file system directly, based on having the path stored somewhere. The user needs to actively _select_ the file, via a file input field or drag&drop. And only in that moment then, when the user is on that page where they selected the file, do you have access to it. Getting access at some later point, without user interaction, is not possible. – CBroe Aug 17 '23 at 10:30
  • @EmreBener I think caching won't solve my problem. Cause I want to upload the image to public server when the scheduling time has come. I don't want to render it. – kaan.py Aug 17 '23 at 10:31
  • if you REALLY need to do this in a web environment (although an OS application or an OS service application would be better suited for the task), web assembly (WASM) might be capable of doing it. I belive WASM can access local files as long as permission is granted. you may have to implement virtual file system. note that javascript simply can't do what you are trying to do. see https://stackoverflow.com/questions/45535301/can-i-read-files-from-the-disk-by-using-webassembly – Emre Bener Aug 17 '23 at 14:08

0 Answers0