I am working on an angular interface based on a fake internal implementation for development.
This fake storage is built using localStorage , and the http request is being processed by e2e $httpBackend . All this works fine until I tried to fake a file upload service.
In my client code, I have the following service ( based on this post ):
angular.module('myApp') .service('fileUpload', ['$http', function ($http) { this.uploadFileToUrl = function(file, uploadUrl) { var fd = new FormData(); fd.append('file', file); $http.post(uploadUrl, fd, { transformRequest: angular.identity, headers: {'Content-Type': undefined} }); }; }]);
and fake boot service:
angular.module('myApp') .run(function($httpBackend, $log) { $httpBackend.whenPOST('api/upload').respond(function(method, url, data) {
FormData Receive FormData . All I read about FormData is that it is a write-only object.
How can I read the contents of a file to save it to local storage?
source share