• This repository has been archived on 23/Apr/2018
  • Stars
    star
    234
  • Rank 171,630 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Upload service with iframe fallback and some nice directives to go with it.

Angular Upload

Upload files using FormData, fall back to iframe upload when FormData isn't supported

  • Works in all browsers
  • Lightweight
  • No dependency on jQuery

Example

<div
  class="btn btn-primary btn-upload"
  upload-button
  url="/upload"
  on-success="onSuccess(response)"
>Upload</div>

Install

Install via bower

bower install --save angular-upload

Add the module to your app dependencies and include it in your page

angular.module('app', [
  'lr.upload'
]);
<script src='bower_components/angular-upload/angular-upload.min.js'></script>

and to your less/css if you want the upload button

@import "bower_components/angular-upload/src/directives/btnUpload.less"; /* or .min.css */

And you are good to go!

Documentation over parameters

Upload button

The upload button masks the normal file input and makes it look like a button

<div
  class="btn btn-primary btn-upload"
  upload-button

  // Mandatory, the url of the backend that is going to handle the upload
  url="/upload"

  // Optional, file param name for upload
  param="file"

  // Optional, object to send as form data with the upload
  data="formData"

  // Optional, comma separated list or array of allowed mimetypes, defaults to allowing all types
  accept="{{acceptTypes}}"

  // Optional, Allow selecting multiple files, defaults to false
  multiple="{{allowMultiple}}"

  // Optional, force all uploads through the iframe solution, defaults to false and should normally not be included
  force-iframe-upload="{{forceIframeUpload}}"

  // Optional, make file input required and add ng-invalid-required if required is set to true on the input button
  required="true|false"

  on-upload="onUpload(files)" // Optional callback when uploading starts
  on-success="onSuccess(response)" // Optional callback
  on-error="onError(response)" // Optional callback
  on-complete="onComplete(response)" // Optional, callback (called on both on-success and on-error)

>Fileupload</div>

Advanced documentation

The upload service that is used behind the scenes in the upload button, can be used in a controller by injecting upload

<body ng-app="app" ng-controller="AppCtrl">
    <input name="myFile" type="file" />
</body>
angular.module('app').controller('AppCtrl', function ($scope, upload) {
  $scope.doUpload = function () {
    upload({
      url: '/upload',
      method: 'POST',
      data: {
        anint: 123,
        aBlob: Blob([1,2,3]), // Only works in newer browsers
        aFile: $scope.myFile, // a jqLite type="file" element, upload() will extract all the files from the input and put them into the FormData object before sending.
      }
    }).then(
      function (response) {
        console.log(response.data); // will output whatever you choose to return from the server on a successful upload
      },
      function (response) {
          console.error(response); //  Will return if status code is above 200 and lower than 300, same as $http
      }
    );
  }
});

Build it yourself!

angular-upload is built with grunt and has a express backend for testing.

Start by installing npm if you don't have it already

via homebrew or homepage (http://nodejs.org/download/)

brew install nodejs

then

npm install -g grunt-cli karma-cli

then from within angular-upload

npm install && bower install

then you can start the testserver up with

grunt webserver

and you can access it through http://localhost:9001 and test the uploader

To run the tests

grunt test

or run in autotest mode

grunt autotest

And when you're done minify it

grunt package

More Repositories

1

play-salat

MongoDB / Salat plugin for Play 2 [MOVED]
Scala
201
star
2

docker-gltf-to-udsz

Docker container for converting gltf files into apple usdz quicklook files
Dockerfile
47
star
3

cordova-plugin-nowplaying

Cordova Plugin Now Playing for iOS
Objective-C
28
star
4

cordova-plugin-remotecommand

Cordova Plugin RemoteCommand
Objective-C
27
star
5

springboot-multiproject

Demo repo for a spring boot multiproject setup
Java
26
star
6

play-enumeration

Scala Enumeration support for Play Framework 2
Scala
19
star
7

akka-command-based-socketserver

Akka 2 command based socket server
Scala
12
star
8

blog-vite-lit-storybook

Article about using vite, lit, storybook, to build standalone web components and publish to npm
TypeScript
11
star
9

blog-angular-cli-bootstrap-font-awesome

Blog Post on how to best integrate bootstrap into an angular-cli app
TypeScript
6
star
10

spring-oauth-social-microservice-starter

Spring authorization server with spring social implementation and jwt microservice intercommunication
Java
6
star
11

leon.github.io

Github Page
HTML
4
star
12

play-ember

Play Framework 2 Ember Plugin
JavaScript
3
star
13

spring-cassandra-messaging-demo

Java
2
star
14

labs-sharp-pano

POF for converting equirectangular images to cube faces
TypeScript
2
star
15

demo-ng-lodash

An example of how to import lodash in an angular project
TypeScript
2
star
16

mash

Mashup platform for the Play Framework
1
star
17

st2-velocity

Sublime Text 2 Velocity plugin
1
star
18

blog-remix-deno

A demo of how to run remix on deno deploy
TypeScript
1
star
19

docker-wordpress-development

Docker images that simply developing wordpress themes / sites
CSS
1
star
20

equi-to-cubemap-wasm

AssemblyScript version of a equirectangular to cubemap converter
TypeScript
1
star
21

gradient-morph-feedback

Feedback for the Gradient Morph Figma Plugin
1
star
22

demo-spring-data-mongodb-mock-data

Load json files into mongodb using Jackson2RepositoryPopulatorFactoryBean
Java
1
star
23

create-babylon

Babylon.js scaffolding via npm init babylon
TypeScript
1
star
24

play-velocity

Velocity ViewEngine
Scala
1
star
25

angular-starter

Angular Starter with bootstrap, font-awesome, ui-bootstrap and routing.
TypeScript
1
star
26

mootools-calendar

A MooTools Calendar
JavaScript
1
star