ndx-file-upload

0.2.4 • Public • Published

ndx-file-upload

file upload/download functionality for ndx-framework apps
all files are encrypted and zipped by default

npm install --save ndx-file-upload

example

bower install --save ng-file-upload

src/client/app.coffee

angular.module 'filedownload', [
  'ndx'
  'ui.router'
  'ngFileUpload'
]

src/client/routes/dashboard/dashboard.ctrl.coffee

angular.module 'filedownload'
.controller 'DashboardCtrl', ($scope, Upload) ->
  $scope.documents = []
  $scope.uploadFiles = (files, errFiles) ->
    if files
      Upload.upload
        url: '/api/upload'
        data:
          file: files
      .then (response) ->
        if response.data
          for document in response.data
            $scope.documents.push document
      , (err) ->
        console.log err
      , (progress) ->
        $scope.uploadProgress = Math.min 100, parseInt(100.0 * progress.loaded / progress.total)
  $scope.makeDownloadUrl = (document) ->
    '/api/download/' + btoa JSON.stringify({path:document.path,filename:document.originalFilename})

src/client/routes/dashboard/dashboard.jade

.dashboard 
  .drop-box(ngf-drop='uploadFiles($files)', ngf-drag-over-class="'dragover'", ngf-multiple='true')
    h3 Drop files here to upload
    button.file-upload(type='file', ngf-select='uploadFiles($file, $invalidFiles)') Or click here to choose
  .document(ng-repeat='document in documents')
    a(href='{{makeDownloadUrl(document)}}', target='_self') {{document.filename}}

methods and callbacks

ndx.fileUpload.on(name, callback)

register a callback

  • upload
  • download

ndx.fileUpload.off(name, callback)

deregister a callback

ndx.fileUpload.download(res, data, filename)

download arbitrary data to the user, eg
src/server/app.coffee

require 'ndx-server'
.config()
.use (ndx) ->
  ndx.app.get '/api/download-csv', (req, res) ->
    ndx.fileUpload.download res, '1,2,3\n4,5,6\n7,8,9', 'mythings.csv'
.start()

src/client/routes/dashboard/dashboard.jade

a(href='/api/download-csv', target='_self') Download CSV

ndx.fileUpload.downloadStream(stream, data, filename)

Readme

Keywords

none

Package Sidebar

Install

npm i ndx-file-upload

Weekly Downloads

6

Version

0.2.4

License

MIT

Unpacked Size

29.9 kB

Total Files

12

Last publish

Collaborators

  • ndxbxrme