I want to send a generated image from a React
frontend to an Express
server but since I can't send a Blob()
object with axios (I get an empty object) my idea was to get the raw image data with Blob().text()
first, send that to the express backend and transform it back to a File()
object there (File()
inherites from Blob()
) but somehow all I get is an blank squared png
which was definetly not what I send.
React
async mint() {
const blob = await htmlToImage.toBlob(document.querySelector('.kryptoweapon'));
const rawPng = await blob.text();
const response = await axios.post('http://localhost:3002/api/mint', {
rawPng,
metadata: this.state
});
}
Express (node)
const { rawPng } = req.body;
const { name, type, blockz, starz } = req.body.metadata;
const nft = {
name,
description: '',
image: new File([rawPng], `blaat.png`, { type: 'image/png' }),
...
}