我正在尝试创建一个名为“资产”的模型,其中包含一系列信息,包括指向上传媒体文件的链接。我发现了几个使用StrongLoop API上传文件的例子,但这些似乎是通过REST API添加文件上传的工作流程,而不是将文件上传与json一起提交到自定义模型。我正在做的一个基本例子是
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();
}
}
如何使用Strongloop管理此工作流程的任何帮助将不胜感激。