KISHAN PATI KISHAN PATI - 1 year ago 101
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 ?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download