gon*_*ard 6 javascript file-upload angularjs angularjs-e2e
我基于假的后端实现开发角度前端.
这个假存储是使用构建的localStorage,http请求由e2e $httpBackend.所有这一切都很好,直到我试图假冒文件上传服务.
在我的客户端代码中,我有以下服务(基于这篇文章):
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}
});
};
}]);
Run Code Online (Sandbox Code Playgroud)
和假上传服务:
angular.module('myApp')
.run(function($httpBackend, $log) {
$httpBackend.whenPOST('api/upload').respond(function(method, url, data) {
// data is a FormData
// TODO
// read the content
// store to local storage
return [200, 'uploaded/path'];
});
});
Run Code Online (Sandbox Code Playgroud)
接收数据是FormData.我读到的FormData只是它是一个只写对象.
如何读取文件内容以将其存储到本地存储中?
| 归档时间: |
|
| 查看次数: |
460 次 |
| 最近记录: |