Way to store data into cookies un-encoded - angularjs

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

Related

file upload queue remain same after refresh?

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

best practice to pass mock data to Angular & Ionic

I am working on an Ionic phone app using AngualrJs as the framework. Now I faced an issue. I don't want my app to send an HTTP request to my backend(which use Ruby on Rails) API to do a manual test.
So I'm wondering what's the best practice to pass a mock JSON data as a response when I want to call the API.
I'm not familiar with Angular and Ionic, I can find some tutorials on both sides but I don't know what's is the best practice if use them together.
You can either store the data in localStorage after the first hit and read the data from localStorage every-time whenever you need.
https://medium.com/#petehouston/awesome-local-storage-for-ionic-with-ngstorage-c11c0284d658
Or you can use
$httpBackend
https://docs.angularjs.org/api/ngMock/service/$httpBackend
by saving json files locally and injecting them back when the application tries to hit the network . One limitation here, you cannot update the json file later after the user have installed the application.
So, localStorage is preferred if you want to cache the data you have received from network.

How to use AngularJS with Struts 1.x

I'm new to AngularJS and client side stuff and I'm adding a new page to an old application that uses Struts 1.3 as its framework. I would like to use AngularJS for the front end.
I know how to return JSON from the action class by writing the JSON to the front end and returning null for the action forward. However, I'm unclear how I would populate the scope variables within the controller after the GET. If I use a GET in the controller and get JSON back, how does my ActionForm fit into all this? Is it useful at all? Can I have a GET and POST for the same controller if I want to send new values back to my action? And, can I have variables like:
$scope.items={}
$scope.items.name=""
$scope.items.email=""
And then just send json.stringify(items) as my data in the POST if I can't use the form somehow?
I haven't found much information using AngularJS with Struts 1.3 so far.
EDIT:
I'll try to answer as best as possible what conclusion I came to but my questions above were very vague since I didn't really know what I was talking about and my position with the company I worked for has ended so I no longer have access to that code. What I meant to ask earlier was what am I going to do with the action form that I usually use for Struts actions and how am I going to get data from the front end to my action class during a POST. I found out that my usual ActionfForm was useless for what I wanted to do so I got rid of it and wrote a JSON object during the GET that would be modified on the frontend and passed back to another action when I did the POST. This is done like a normal POST to whateverAction.do, but I had to configure the data I was sending in the POST and name it something. I then picked up the modified JSON object by using
request.getParameter("jsonObjName")
and parsed it to different LinkedHashMap objects for each object in the JSON object. I think you can use the JSONObject classes instead of LinkedHashMap to parse if you are using JavaEE but I was using SE so I didn't have access to those in this project. Here a link to another page I used for the POST configurations:
How to get the data in Struts from AngularJS post
On the Java side you can also try to use Gson library that allows you to parse string to and from JSON, but Struts 1 generally won't fit well with AngularJS, if you remove the form on Java side, than makes no sense to keep Struts 1.
And if no possibility to remove Struts 1, than just keep Struts 1 for existing functionality and start using Struts 2 for new screens where AngularJS is applied.
It will be much easier cause the JSON from AngularJS' POST will automatically be bound to the bean object that has to match to JSON properties format and name.

Web API null parameter value in POST action

I'm trying to use angular and asp.net vNext Web API. I have a controller up but when using angular's $resource the object values are not resolved (Post method parameter is null)
The request itself has nothing out of the ordinary, though it does send json back. I think I've seen somewhere that vNext doesn't support content negotiation yet so maybe that's it. Can anyone confirm or shed some light on the subject?
Also - is there a way to get to the raw post data in Web API? (I'm using the core framework) cause the Request.Form that I know from mvc is not there any more. I tried the GetFormAsync but that returns an empty collection.
EDIT:
Confirmed that the reason for not binding the parameter is the fact that data is sent as JSON. When form encoding is used, the parameter values are resolved correctly.
using [FromBody] attribute on the param solved the issue.

how to send/receive data securely in backbone.js

I have created RESTFUL urls that respond with some JSON data when fetched by backbone.
So a url like /lists responds with a json array of user-created lists. My want that if the url is accessed by address bar input like mydomain.com/lists, the json data is displayed in text on browser. I want the server to respond only if the url is accessed from within the application. Can somebody provide me some hints on how to achieve this?
Like #Thilo said, you're not going to be able to do prevent a person with the right tools to see what's coming across the wire, Firebug's console/net tabs already keep track of requests and show the contents of responses.
That being said, what you can do is check whether the HTTP_X_REQUESTED_WITH HTTP header is set to 'XMLHttpRequest', and only return the JSON in this case. Backbone makes an Ajax call so this will always be the case with the Backbone calls (in modern browsers). Again this won't help much except for people who type it into the address bar directly (and do a normal GET request) won't see the JSON.

Resources