3

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.

Anoop Thiruonam
  • 2,567
  • 2
  • 28
  • 48
user1514915
  • 111
  • 9
  • I am exactly trying to do the same thing, but no luck yet. Cannot figure out what to give to the storage service API for uploading the file, neither how to get that file server-side. Do you have any updates on this question ? – Overdrivr Jan 04 '16 at 16:34
  • 1
    Possible duplicate of http://stackoverflow.com/questions/28885282/how-to-store-files-with-meta-data-in-loopback – Overdrivr Jan 10 '16 at 10:50

0 Answers0