我想将二进制文件中的二进制数据提取到字节数组中.我很难让它正常工作.
你可以在这里看到jsFiddle:https://jsfiddle.net/alexsuch/6aG4x/
HTML:
<div ng-controller="MainCtrl" class="container">
<h1>Select text file</h1>
<input type="file" on-read-file="showContent($fileContent)" />
<div ng-if="content">
<h2>File content is:</h2>
<pre>{{ content }}</pre>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
Javascript代码:
var myapp = angular.module('myapp', []);
myapp.controller('MainCtrl', function ($scope) {
$scope.showContent = function($fileContent) {
$scope.content = $fileContent;
};
});
myapp.directive('onReadFile', function ($parse) {
return {
restrict: 'A',
scope: false,
link: function(scope, element, attrs) {
var fn = $parse(attrs.onReadFile);
element.on('change', function(onChangeEvent) {
var reader = new FileReader();
reader.onload = function(onLoadEvent) {
scope.$apply(function() {
fn(scope, {$fileContent:onLoadEvent.target.result});
}); …Run Code Online (Sandbox Code Playgroud) javascript binaryfiles mongodb angularjs angularjs-directive