1

I'm trying to upload a pdf file to my local storage, using javascript, but no tutorial I used seems to work.

I have my 'add function' in my service:

add(title, description) {
    let old = JSON.parse(localStorage.getItem('list')) || [];
    let new  = {
        'title':       title,
        'description': description,
    };
    old.push(newBook);
    this.object = old;
    localStorage.setItem('list', JSON.stringify(old));
};

And I don't know how to also add a pdf file. This is how the html looks for the above code:

    <input class="title"
              label="Title"
              type="text"
              input-id="title"
              bind="$ctrl.title"
              placeholder="AddTitle">
    </input>

    <input class="description"
              label="Description"
              type="text"
              input-id="description"
              bind="$ctrl.description"
              placeholder="Add Description">
    </input>

    <button theme="" on-click="$ctrl.addElement()">Add</button>

The input and button are components* Next on the controllers add functionality:

addElement() {
    this.Service.add(this.title, this.description);
}

How do I go about adding the pdf file and saving it to the local storage, so that I can even download it later?

Kyuubido0
  • 55
  • 1
  • 9
  • https://stackoverflow.com/questions/19119040/how-do-i-save-and-restore-a-file-object-in-local-storage – Suresh Kamrushi Jun 30 '17 at 08:45
  • That workaround uses jquery and saves the file object by making a copy of the image data. I can't use jquery. And the other solution saves a generic object, not a file object. @SureshKamrushi – Kyuubido0 Jun 30 '17 at 08:50

1 Answers1

1

These links seems helpful and are worth trying. You can use indexed DB.

http://hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb/ https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API

While Web Storage is useful for storing smaller amounts of data, it is less useful for storing larger amounts of structured data. IndexedDB provides a solution.

Hope that helps !

Louis Lecocq
  • 1,764
  • 3
  • 17
  • 38