javascript - 在 laravel 中上传具有多个文件的元数据
问题描述
我想用元数据在 laravel 中上传多个文件。像文件自定义名称和文件类别。
我尝试使用 js 在前端添加一些属性,但我可以在控制器中看到它们这里的代码
$(document).on('change','#file',function(e){
let file = e.target.files[0]
file.totalWords = 1234;
file.caytegory = 'category';
filesList.push(file)
});
let mainFormData = new FormData();
filesList.forEach(file => {
mainFormData.append('files[]',file)
})
$.ajax({
data: mainFormData,
url: 'controller_url',
type: "POST",
processData: false,
contentType: false,
headers: {
Accept : "application/json"
},
success: function (data) {
console.log(data)
});
},
error: function(response) {
console.log(response);
}
});
这是我的控制器
return response()->json($request->file('files')[0]->caytegory);
我想要的只是从提交的文件中访问类别属性,但我不能
解决方案
推荐阅读
- node.js - 两台服务器之间建立Node JS连接
- flutter - Flutter 的 Flare 动画可以应用于交互式 UI 元素吗?
- java - Java中给定字符串的最长子序列
- java - VS 代码 Java 调试器
- currency - 交易视图中的独立指标
- java - 如何在 gradle 中导入外部依赖项?
- python - pandas groupby 两列并从第二列生成列
- angular - 当我尝试通过whatsapp共享链接时,在离子应用程序中收到消息**共享失败请重试**
- wordpress - Visual-composer 后端编辑器不适用于最新版本的 wordpress(5.0 版)
- ios - 如何在 iOS 的 Numbers 中存储像“2.3.1”这样的值?