A module for FeedHenry RainCatcher that manages files. It provides :
- Backend services that expose REST endpoints to create and read operations for files .
- Frontend directives and services providing a REST client for files.
This module is packaged in a CommonJS format, exporting the name of the Angular namespace. The module can be included in an angular.js as follows:
angular.module('app', [
, require('fh-wfm-file')
...
])
This module provides a injectable file service : fileClient
Example of read
usage :
resolve: {
files: function(fileClient, profileData) {
return fileClient.list(profileData.id);
}
}
Example of upload
usage :
camera.capture()
.then(function(dataUrl) {
return fileClient.uploadDataUrl(profileData.id, dataUrl)
});
Example of re-init/restarting fileTransfer queues :
fileClient.processQueue()
.then(function(hasJobs) {
console.info('Found job to process in queues, starting file-Transfer');
}, function() {
console.info('No jobs to process currently, file-Transfer idle.');
})
Example of saving/persisting fileTransfer queues :
fileClient.persistQueue()
.then(function(success) {
console.info('file-Transfer queues have been saved!');
}, function(error) {
console.error('Problem saving fileTransfer queues!: ', error);
});
Example of saving/persisting fileTransfer queues :
fileClient.persistQueue()
.then(function(success) {
console.info('file-Transfer queues have been saved!');
}, function(error) {
console.error('Problem saving fileTransfer queues!: ', error);
});
Example of adding item to uploads
queue :
camera.capture()
.then(function(dataUrl) {
return fileClient.uploads.addItem({
id: profileData.id,
fileName: 'my-super-img-file.png'
fileURi: dataUrl,
createdTs: Date.now(),
status: 'waiting',
retries: 3,
userId: 'trever',
step: 'rsik-assessment',
result: this.model
})
});
For a more complete example around files operations, please check the demo mobile app.
name | wfm-img |
---|---|
purpose | retrieves image file from the cloud |
args | uid of the file |
example | <img wfm-img uid="ctrl.file.uid" style="width:450px"> |
name | file-detail |
---|---|
purpose | presents file details as a list, takes options to select which details it will show. |
args | file : file object, display-options : array of file attributes e.g. self.displayOptions = {id: true, name: true, uid: true, owner: true, preview: true}; |
|
| example | <file-detail file="ctrl.file" display-options="ctrl.displayOptions"></file-detail>
|
The server-side component of this WFM module exports a function that takes express and mediator instances as parameters, as in:
var express = require('express')
, app = express()
, mbaasExpress = mbaasApi.mbaasExpress()
, mediator = require('fh-wfm-mediator/lib/mediator')
;
// configure the express app
...
// setup the wfm user router
require('fh-wfm-file/lib/router')(mediator, app);
Base url : /file/wfm
resource | method | returns |
---|---|---|
/all | GET | array of files |
/owner/:owner | GET | filtered array of files |
/owner/:owner/upload/base64/:filename | POST | file metadata |
/upload/binary | POST | file metadata |
the module publishes following topics:
-
wfm:file:detail:close
- on file detail view close.Client app example:
mediator.subscribeForScope('wfm:file:detail:close', $scope, function() { $state.go('app.file'); });
{
owner: req.params.owner,
name: req.params.filename,
uid: uuid.create().toString()
}