我正在使用https://marmelab.com/admin-on-rest/RestClients.html#decorating-your-rest-client-example-of-file-upload上显示的代码将图片上传到服务器。但是此代码仅返回同一字段上的多个图像。 如何在不同的字段中上传多个图像?
const addUploadCapabilities = requestHandler => (type, resource, params) => {
if (type === 'UPDATE' && resource === 'posts') {
if (params.data.pictures && params.data.pictures.length) {
// only freshly dropped pictures are instance of File
const formerPictures = params.data.pictures.filter(p => !(p instanceof File));
const newPictures = params.data.pictures.filter(p => p instanceof File);
return Promise.all(newPictures.map(convertFileToBase64))
.then(base64Pictures => base64Pictures.map(picture64 => ({
src: picture64,
title: `${params.data.title}`,
})))
.then(transformedNewPictures => requestHandler(type, resource, {
...params,
data: {
...params.data,
pictures: [...transformedNewPictures, ...formerPictures],
},
}));
}
}
}