我有一个API(由Lumen创建)来保存客户端的图像或文件.
这是我的API代码
if ($request->hasFile('image')) {
$image = $request->file('image');
$fileName = $image->getClientOriginalName();
$destinationPath = base_path() . '/public/uploads/images/product/' . $fileName;
$image->move($destinationPath, $fileName);
$attributes['image'] = $fileName;
}
Run Code Online (Sandbox Code Playgroud)
我已经在邮递员中尝试了API,一切顺利,图像成功上传.
从客户端发送图像(调用API)并将图像保存在API项目中的最佳做法是什么?因为我的代码无效
这是我尝试在客户端接收图像文件时的代码,然后调用API.
if ($request->hasFile('image')) {
$params['image'] = $request->file('image');
}
$data['results'] = callAPI($method, $uri, $params);
Run Code Online (Sandbox Code Playgroud) 所以我有一个var data结果数组JSON值,如下所示:
[
{"vehicle_id":"1", "model_name":"sedan"},
{"vehicle_id":"2", "model_name":"elf"},
{"vehicle_id":"3", "model_name":"truck"}
]
Run Code Online (Sandbox Code Playgroud)
我想在新变量上设置每个值,如下所示:
var newdata = [
{
text: Obj.model_name
value: Obj.vehicle_id
},
{
text: Obj.model_name
value: Obj.vehicle_id
},
......
];
Run Code Online (Sandbox Code Playgroud)
如何设置上面变量的每个值?
我已经尝试过这种方法:
var newdata = [
$.each(data, function(index, Obj){
{
text: Obj.model_name
value: Obj.vehicle_id
}
})
];
Run Code Online (Sandbox Code Playgroud)
但似乎它不起作用,任何人都可以有这种情况的最佳做法吗?