Reactjs React.js将文件上载到服务器
我正在努力学习如何通过圣殿认证对Laravel 8作出反应。我正在尝试使用Reactjs React.js将文件上载到服务器,reactjs,laravel-8,react-dropzone,Reactjs,Laravel 8,React Dropzone,我正在努力学习如何通过圣殿认证对Laravel 8作出反应。我正在尝试使用React将文件上载到服务器。我正在使用react dropzone拖动和预览图像,这里是react dropzone代码 const { getRootProps, getInputProps } = useDropzone({ accept: "image/*", onDrop: (acceptedFiles) => { setFiles( acce
React
将文件上载到服务器。我正在使用react dropzone
拖动和预览图像,这里是react dropzone代码
const { getRootProps, getInputProps } = useDropzone({
accept: "image/*",
onDrop: (acceptedFiles) => {
setFiles(
acceptedFiles.map((file) =>
Object.assign(file, {
preview: URL.createObjectURL(file),
})
)
);
},
});
我正在获取文件和它的预览。这是我用来上传到服务器的上传代码
const data = new FormData();
files.map((file) => data.append("images", file));
apiClient.get("sanctum/csrf-cookie").then(() => {
apiClient
.post("api/upload/image/1", data, {
headers,
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.dir(err);
toast.error("Something Went Wrong");
})
})
在Laravel上,我试图通过
$request->all()
但它又回来了
images:{}
您需要通过文件
函数或作为对象属性(例如->images
而不是全部
来捕获它
更多信息:我正在尝试上载多张图像。如何在一个场景中捕捉所有喜欢的内容array@HamzaAfzal循环它的值。我忘了用图像添加[]