I'm attempting to create a model called an "asset" which includes a bunch of information including a link to an uploaded media file. I've found several examples of file uploads using the StrongLoop API but these seem to be workflows for adding file uploads via the REST api rather than including file uploads to be submitted along with json to a custom model. A basic example of what I'm doing is below
index.html
// Can't use multipart/form as the model needs to receive json data
<form method='POST' enctype='application/json' action="http://localhost:3000/api/assets">
<input type="text" id="title" name="title" value="The title"><br>
<input type="text" name="foo" value="bar"><br>
<input type="file" name="file"><br>
<input type="submit">
</form>
_
common/models/asset.js
module.exports = function(Asset) {
Asset.beforeCreate = function(next, modelInstance){
console.log(modelInstance.file);
// This object includes the file name as a string but naturally
// doesn't include the file. Ideally at this point I'd like to use the
// StorageService api to save the file on the server here
// before creating the rest of the model.
next();
}
}
Any help with how to manage this workflow with Strongloop would be greatly appreciated.