azure-mobile-apps-files
This is a plugin for the Azure Mobile Apps Node.js server that adds simple
yet powerful file storage capabilities. It is intended to be used with the
file management plugin for the Azure Mobile Apps client SDKs.
For more information, see https://azure.microsoft.com/en-us/blog/file-management-with-azure-mobile-apps/.
Installation
npm i --save azure-mobile-apps-files
The azure-mobile-apps server detects the presence of the file
management plugin and loads it automatically.
Usage
First, add a storage account data connection using the Data Connections section
of the portal.
File management can then be added to a table by simply adding a files property
to a table definition:
var app = require('express')(),
mobileApp = require('azure-mobile-apps')()
mobileApp.tables.add('todoitem', { files: true })
app.use(mobileApp)
app.listen(process.env.PORT || 3000)
However, this leaves access to the file storage completely open and
unauthenticated. It is recommended to add some sort of validation to requests.
A simple, contrived example:
var table = module.exports = require('azure-mobile-apps').table()
table.access = 'authenticated';
table.files = {
token: function (storage, context) {
var permission = context.user.id === 'admin' ? 'all' : 'read';
return storage.token(permission)
},
delete: function (storage, context) {
if(context.user.id === 'admin')
return storage.delete(context.req.params.blobName)
context.res.status(401).send("Only the administrator can delete files")
}
}
API
The storage
parameter that is passed to each function in the above example
has the following structure:
var storage = {
token: function (permission, blobName) {
},
list: function () {
},
delete: function (blobName) {
}
}
By default, there is one container per table row.
The context
parameter is the normal azure-mobile-apps context object,
described at http://azure.github.io/azure-mobile-apps-node/global.html#context.
Running Tests
git clone https://github.com/Azure/azure-mobile-apps-node-files.git
cd azure-mobile-apps-node-files
npm i
npm test
More Information
For more information on using file management on the client, see
https://azure.microsoft.com/en-us/blog/file-management-with-azure-mobile-apps/
License
MIT