我得到了以下表格 - 我可以轻松地在打字稿中“附加”根
fruit_image
属性的文件,但当它是文件所在的给定类型列表 fruits[0]
的一部分时则不能。如何做到这一点?
import fs from 'fs';
import path from 'path';
const fruitImage = fs.readFileSync(path.resolve(__dirname, './fruit-image.png'));
export const form = () => {
return {
id: 'some id',
//below ok - got byte array
fruit_image: {
name: 'fruit-image.png',
mimeType: 'png',
buffer: fruitImage,
},
//below is not ok - posting this to endpoint results in null list
fruits: [
{
id: 'banana',
fruit_image: { name: 'fruit-image.png', mimeType: 'png', buffer: fruitImage }
}
]
};
};
而不是这个:
//below is not ok - posting this to endpoint results in null list
fruits: [
{
id: 'banana',
fruit_image: { name: 'fruit-image.png', mimeType: 'png', buffer: fruitImage }
}
]
这个:
'fruits[0].id': 'banana',
'fruits[0].fruit_image': { name: 'fruit-image.png', mimeType: 'png', buffer: fruitImage }