KISHAN PATI KISHAN PATI - 3 months ago 8
AngularJS Question

How to drag external files into the browser using AngularJS

In my project i want to drag external files with extension ".opgs" into the browser drop zone.

How can i achieve this using angular js ?


I used an module: ng-file-upload -

Install with bower bower i ng-file-upload -S.

Load it in your head tag:

<script src="/admin/assets/vendor/ng-file-upload/ng-file-upload.min.js"></script>

You hook the drop action to your dom element like this:

<div ngf-drop="upload($files)"></div>

Inject it into your app:

your_app = angular.module('your_app', ['ngFileUpload'], function () {

Then you get the file in the controller like this:

$scope.upload = function (file) {

    var extension = file[0].name.match(/\.(.*)$/)[0]

    if (extension == 'opgs') {

Works quite well.