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 =mobileApp =mobileApptablesappapp
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 = moduleexports =tableaccess = 'authenticated';tablefiles ={// give the admin user full permission, read for all other authenticated usersvar permission = contextuserid === 'admin' ? 'all' : 'read';return storage}// allow any authenticated user to list files// list: function (storage, context) {// return storage.list()// },{ifcontextuserid === 'admin'return storagecontextresstatus401}
API
The storage
parameter that is passed to each function in the above example
has the following structure:
var storage ={// permission is one of 'read', 'write', 'readwrite', 'create', 'delete', 'list' or 'all'// alternatively, any permission understood by the Azure Storage REST API, any of 'rwdla'// blobName is optional, if omitted, the token is for the container}{// list all files in the container}{// delete the specified blob from the container}
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