QTI

qti.vn. Được tạo bởi Blogger.

Thứ Tư, 13 tháng 7, 2016

AngularJs: How to check for changes in file input fields?


No binding support for File Upload control
https://github.com/angular/angular.js/issues/1375
<div ng-controller="form-cntlr">
        <form>
             <button ng-click="selectFile()">Upload Your File</button>
             <input type="file" style="display:none" 
                id="file" name='file' onchange="angular.element(this).scope().fileNameChanged(this)" />
        </form>  
    </div>
instead of
 <input type="file" style="display:none" 
    id="file" name='file' ng-Change="fileNameChanged()" />
can you try
<input type="file" style="display:none" 
    id="file" name='file' onchange="angular.element(this).scope().fileNameChanged()" />
Note: this requires the angular application to always be in debug mode. This will not work in production code if debug mode is disabled.
and in your function changes instead of
$scope.fileNameChanged = function() {
   alert("select file");
}
can you try
$scope.fileNameChanged = function() {
  console.log("select file");
}
Below is one working example of file upload with drag drop file upload may be helpful http://jsfiddle.net/danielzen/utp7j/
Angular File Upload Information
URL for AngularJS File Upload in ASP.Net
http://cgeers.com/2013/05/03/angularjs-file-upload/
AngularJs native multi-file upload with progress with NodeJS
http://jasonturim.wordpress.com/2013/09/12/angularjs-native-multi-file-upload-with-progress/
ngUpload - An AngularJS Service for uploading files using iframe
http://ngmodules.org/modules/ngUpload

FileReader.readAsDataURL()


The readAsDataURL method is used to read the contents of the specified Blob or File. When the read operation is finished, the readyState becomes DONE, and the loadend is triggered. At that time, the result attribute contains  the data as a URL representing the file's data as a base64 encoded string.

Syntax

instanceOfFileReader.readAsDataURL(blob);

Parameters

blob
The Blob or File from which to read.

Example

HTML

<input type="file" onchange="previewFile()"><br>
<img src="" height="200" alt="Image preview...">

JavaScript

function previewFile() {
  var preview = document.querySelector('img');
  var file    = document.querySelector('input[type=file]').files[0];
  var reader  = new FileReader();

  reader.addEventListener("load", function () {
    preview.src = reader.result;
  }, false);

  if (file) {
    reader.readAsDataURL(file);
  }
}

Live Result



Example reading multiple files

HTML

<input id="browse" type="file" onchange="previewFiles()" multiple>
<div id="preview"></div>

JavaScript

function previewFiles() {

  var preview = document.querySelector('#preview');
  var files   = document.querySelector('input[type=file]').files;

  function readAndPreview(file) {

    // Make sure `file.name` matches our extensions criteria
    if ( /\.(jpe?g|png|gif)$/i.test(file.name) ) {
      var reader = new FileReader();

      reader.addEventListener("load", function () {
        var image = new Image();
        image.height = 100;
        image.title = file.name;
        image.src = this.result;
        preview.appendChild( image );
      }, false);

      reader.readAsDataURL(file);
    }

  }

  if (files) {
    [].forEach.call(files, readAndPreview);
  }

}
Note: The FileReader() constructor was not supported by Internet Explorer for versions before 10. For a full compatibility code you can see our crossbrowser possible solution for image preview. See also this more powerful example.

Specifications

SpecificationStatusComment
File API
The definition of 'FileReader' in that specification.
Working DraftInitial definition

Browser compatibility

FeatureFirefox (Gecko)ChromeInternet ExplorerOperaSafari
Basic support3.6 (1.9.2)[1]710[2]12.02[3]6.0
[1] Prior to Gecko 2.0 beta 7 (Firefox 4.0 beta 7), all Blob parameters below were Fileparameters; this has since been updated to match the specification correctly. Prior to Gecko 13.0 (Firefox 13.0 / Thunderbird 13.0 / SeaMonkey 2.10) the FileReader.error property returned a FileError object. This interface has been removed and FileReader.error is now returning the DOMError object as defined in the latest FileAPI draft.
[2] IE9 has a File API Lab.
[3] Opera has partial support in 11.1.

See also

Thứ Tư, 6 tháng 7, 2016

MongoDB 2.6 does not start on Ubuntu 15.04


I installed from the debian wheeze repository and it works fine.
First make sure you remove the mongodb-org package and all its dependencies:
sudo apt-get purge mongodb-org
sudo apt-get autoremove
Remove the old mongodb.list you created:
sudo rm /etc/apt/sources.list.d/mongodb.list
Use the Debian repository instead:
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
Update and install again:
sudo apt-get update
sudo apt-get install -y mongodb-org
After that, you can succesffully start the server:
sudo service mongod start
or
systemctl start mongod
(as clarified by Ernie Hershey in reply to Roman Gaufman's comment here: https://jira.mongodb.org/browse/SERVER-17742)