DreamFactory:如何将图像上传到文件服务器并在DataBase中保存图像的路径?

时间:2016-02-16 13:13:04

标签: database post save store dreamfactory

我正在考虑将DreamFactory用作API。我在服务器逻辑上很新鲜。我想将文件系统上的图像和存储文件的路径存储到数据库中。我不会将图像作为blob存储在数据库中,因为它们将会跟随许多其他图像。有人可以指出我正确的方向吗?

首先使用以下方法将图像发布到文件系统:

post /files/{file_path} 

之后:

post /mysql/_table/{table_name} createRecords() - Create one or more records

但是如何将路径传递给数据库?

1 个答案:

答案 0 :(得分:1)

一种方法是在POST到/ files / {file_path}上使用服务器端脚本(在本例中为V8J)。转到管理应用程序,脚本选项卡,然后按事件处理以下路径......

Process Event Scripts > files > files.{file_path} > [POST] files.{file_path} > files.{file_path}.post.post_process

尝试以下脚本......

// event.resource is the {file_path} part, 
// including any folders from root, i.e. my/path/file.txt
var_dump(event.resource); 

// Create a record that you want to post to a table, 
// using the "todo" table for example, setting "name" to the file path
// "mysql" is my db service name
var record = {"resource": [ {"name": event.resource, "complete": false } ] }; 
var result = platform.api.post('mysql/_table/todo', record);

var_dump(result); 
// result contains a resource array with the id of the record created
// like {"resource": [ {"id": 5} ] }