我使用ng-file-upload在我的项目中上传图片但是
每当我使用localStorage
AuthFactory.setToken({token: "secret_token", expires: 'time'});
实施ng-file-upload
时,无法将图像发送到服务器。它与AuthFactory.setUser(user_obj)
.factory('AuthFactory', ['LSFactory', function(LSFactory) {
var userKey = 'user';
var tokenKey = 'token';
var AuthAPI = {
isLoggedIn: function() {
return this.getUser() === null ? false : true;
},
getUser: function() {
return LSFactory.get(userKey);
},
setUser: function(user) {
return LSFactory.set(userKey, user);
},
getToken: function() {
return LSFactory.get(tokenKey);
},
setToken: function(token) {
return LSFactory.set(tokenKey, token);
},
deleteAuth: function() {
LSFactory.delete(userKey);
LSFactory.delete(tokenKey);
}
};
return AuthAPI;
}])
.factory('LSFactory', [function() {
var LSAPI = {
clear: function() {
return localStorage.clear();
},
get: function(key) {
return JSON.parse(localStorage.getItem(key));
},
set: function(key, data) {
return localStorage.setItem(key, JSON.stringify(data));
},
delete: function(key) {
return localStorage.removeItem(key);
},
getAll: function() {
var books = [];
var items = Object.keys(localStorage);
for (var i = 0; i < items.length; i++) {
if (items[i] !== 'user' || items[i] != 'token') {
books.push(JSON.parse(localStorage[items[i]]));
}
}
return books;
}
};
return LSAPI;
}])