file upload queue remain same after refresh? - angularjs

I am using angular file upload for my project. referring the below link I have worked my project
http://nervgh.github.io/pages/angular-file-upload/examples/simple/
My requirement is once I select a file or multiple file if I refresh also it should not remove from the queue.
I tried to use localstorage but its not working
Here is the code where I have used local storage.
uploader.onAfterAddingAll = function(addedFileItems)
{
console.info('onAfterAddingAll', addedFileItems);
$localStorage.allfiles= addedFileItems;
};
At the end I did get console but it is showing empty.
console.log($localStorage.allfiles);
Please any one can help on this will be a great help

Ok so before starting please go through MDN Web Storage API. It states that
The Web Storage API provides mechanisms by which browsers can store key/value pairs, in a much more intuitive fashion than using cookies.
So localStorage can store key value pairs and as of now only string values are supported. It can not store files. So you wont be able to achieve what you are trying as you want to store file and that's not supported.
Also if you want to store objects you will have to stringify them and then store.
One suggested solution i have is you can convert your files to a bytes array and then store them and then you can handle those bytes the way you want.
Also this might help you I think thats waht you want . Mozilla Hacks Storing Images in localStorage
Once the image is saved as data url which is base 64 encode. You just need to send the string to the server and decode it with base 64

Related

React Native Data Base

Ok... I am so confused. I am new to React Native and I have created a simple mobile app that shows a list of news (containing a specific image, title, and description). I have a lot of experience with programming most of which comes from game development. I have created many games and I am familiar to cloud storage systems that you update and retrieve data.
Right now I just have a local json file with an array of 'news' Objects and then I loop through this array to show the news posts. Basically, I want to move this json file to somewhere online where the app just retrieves it. This would make it so that the News json file could be edited in order to change, add or remove new news. So, I don't need account or anything. I don't even need to be able to set/update data from the app. I just need a place to store images and files that can be retrieved from the app.
I have tried using the common react native data base systems like sqlite, realm, mongodb, and firebase, but must not understand how they work because they make no sense. Also, it seems like when making a mobile app all of these services require you to setup a backend and start a server, which from what I can tell doesn't work on mobile... It seems logical that there would be a global data base that I could store storage on and just receive it by a simple fetch or network call. Am I totally crazy here ?:) Any help or guidance is super appreciated. Thanks.

Alternatives to the Query-string managing state

We're using React redux, which is fantastic. However, the moment someone refreshes their browser we lose the Redux store and as a result the application breaks or needs to redirect back to the 'start'.
We are using the Query-string to manage this, but I have been told Management this is 'Ugly' and we should find an alternate place to hold this information and remove it from the URL.
My understanding is we could use a number of things; Cookies, local storage, session storage etc.
However, I don't know which is the best to use.
We're essentially just looking for somewhere to move the information contained in the URL. E.G. https://url.com?querystring=12345&non-sensitive-id=2242
Edit: We're using Typescript, so ideally having a typesafe option would be ideal. We can achieve this with querystrings.
You can use localStorage of HTML5.
To store data:
//To store data:
localStorage.setItem("key", 'value');
//To access data:
localstorage.getItem("key");
//and to remove from local storage,
localStorag.removeItem("key");

How to store and get data from JSON?

I want to make a forums in Angular JS for which I want to make few JSON data files where I can store and get data from. Some of the problems to keep in mind.
I want to add new data from the browser not adding it to the data file directly. Thank you for the assistance
If you're just dealing with small amounts of data, JSON is fine, but if your datasets get large, definitely switch to a database like MongoDB or DynamoDb.
In the browser you can use LocalStorage to store your JSON payloads and you can access using a plugin like lawnchair:
http://brian.io/lawnchair/

Where does the data's are stored when using Backbone.localstorage()?

im doing a sample todo application by using a tutorial .. In that they are using Backbone.localstorage , my doubt is Where does the data's will be stored when using Backbone.localstorage()?
localstorage will save all of your todos data within your browser, instead of sending them to a server.
-So that when you use Backbone.localstorage() the data is with you in your browser than to store it on server side and will get accessed from browser only
-You may refer the link http://backbonejs.org/
Do you want this?
I'm taking this on http://todomvc.com/architecture-examples/backbone/
Want to know what is localstorage indeed?
See it in your computer:
C:\Users\YourUserName\AppData\Local\Google\Chrome\User Data\Default\Local Storage
You will find
http_todomvc.com_0.localstorage
If you try to edit the file with your notepad, you will find it's a sqlite3 datebase indeed.

Way to store data into cookies un-encoded

Is there a way I can add data into a cookie as is?
I am using my encoding logic and don't want angularjs to do any further encoding on the data.
Edit:
Example:
I want to store the following into a cookie
KdjeI7astAO2l/+cwmoqN1OXjKjLauG7a5Ylf9I57Ok+lmNmp7hBNcqkwAigJGDXbo6TRSJsMaT7jT4EBF1hBA==
using $cookies.mycookie = ...
But AngularJs seems to encode my data to
KdjeI7astAO2l/+cwmoqN1OXjKjLauG7a5Ylf9I57Ok+lmNmp7hBNcqkwAigJGDXbo6TRSJsMaT7jT4EBF1hBA%3D%3D
Is there anyway to have AngularJs store my original data without any modification.
Edit 2:
Also upon further digging I found this link https://github.com/angular/angular.js/issues/3414 which explains that angular is doing encoding when storing cookie. As I previously asked what will be the way to store data in a cookie without this encoding in angular.
The Angular $cookie function will escape your data when storing a cookie, and unescape it when it is retrieved.
If you don't want this to happen, don't use the Angular implementation. You can simply set the cookie yourself using the native browser cookie API, document.cookie: https://developer.mozilla.org/en-US/docs/Web/API/document.cookie

Resources