We will try to be very carefull with this one and warn people upfront. As of today, I don’t expect the PLMAPI to store much files by itself. If we believe we want PLM to become spread into more services in order to share some of the ressources accorss multiple domains (PLM is not the only system to consume files why should we have a different setup than ERP?).
But in the mean time, it is nice to have it as an option and we will see later how to interact with files if they are hosted by other services.
With Sails (the framework we use for this project for now) it is pretty easy to add the file api. You just have to run in the command line
sails generate api file
It creates a model and a controller, and you need to create a view for the upload form to start (which can be used in many other context) and a controller method to handle the upload request.
Who said PLMAPI was only about the webservice. Sometimes I like to get into designing some interfaces. Here is the file upload form I made based on a codrop article.
And this is obviously open source, so the source is here : https://github.com/YMA-MDL/PLMAPI/blob/master/PLMAPI/views/fileupload.ejs
The upload handler – controller method
Once you selected one or more files and push the upload button, if everything works well, you should get this kind of answer.
How is this done? well, look at the controller : https://github.com/YMA-MDL/PLMAPI/blob/master/PLMAPI/api/controllers/FileController.js
Where is it stored?
For now it just uploads on a local folder but the target is to have each account (an account = a company = multiple users) having to fill some storage informations like an Amazon S3 location and credentials in order to store each companies files on the cloud.
Not a tone of code, right ?