Loading the Strongloop file inside the model

I am trying to create a model called "asset" that includes a bunch of information, including a link to a downloaded media file. I found some examples of file uploads using the StrongLoop API, but they seem to be workflows for adding file uploads via the REST api, rather than adding files to send along with json to the custom model. Basic example of what I am 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 on how to manage this workflow with Strongloop would be greatly appreciated.

+3


source to share





All Articles