saving an array of objects in a session

146 views Asked by At

This is a snippet of my code that runs every time a file gets added to the uploader (dropzone.js). The files are not immediately uploaded but are rather stored in a queue. I would like to be able to maintain this queue throughout post backs.

        var myDropzone = this;
        var filesUploaded;
        myDropzone.on("addedfile", function () {
                filesUploaded = myDropzone.getQueuedFiles();
                myDropzone.queuedFiles = filesUploaded; // this should be set on each
// postback to be equal to the filesUpload that existed before the postback
            });

The files in myDropzone.queuedFiles should remain after a post back occurs. I would like to have the uploaded files still visible in the uploader, that way user does not need to re-select their files.

I'm new to web dev and I've tried using sessionStorage but I was unable to implement anything working. I'm working with JavaScript (jQuery), ASP.NET and using dropzone.js as the uploader.

I do realize that myDropzone.queuedFiles = filesUploaded should only be run when a post back has happened and we have saved the information from filesUploaded into something we can maintain and access after a postback. How would I do that?

1

There are 1 answers

0
debiasej On

Did you try with localStorage? I think your problem is sessionStorage instead of localStorage.

HTML local storage provides two objects for storing data on the client:

window.localStorage - stores data with no expiration date.

window.sessionStorage - stores data for one session (data is lost when the tab is closed)

Take a look at these links:

Pass datepicker object between pages

HTML5 Local Storage