Hello there,
having the hardest time with this one.
I’m trying to upload QR codes images generated with the Google QR API,
but I’m getting 406 error.
Here is my code:
const code = `https://chart.googleapis.com/chart?cht=qr&chs=128x128&chl=https://www.elcuchillo.mx/cupones?id=7e97049f-524a-4797-9ef0-5e6992169a9e&choe=UTF-8`;
//console.log(code);
return fetch(code,
{
method: 'GET',
headers:
{
'Content-Type': 'image/png'
}
})
.then(async (Response) => {
if (Response.ok) {
const textData = await Response.text();
//console.log(textData);
const b = Buffer.from('data:image/png;base64,' + textData, 'base64');
console.log(b);
return mediaManager.upload("/UPLOADS", b, "7e97049f-524a-4797-9ef0-5e6992169a9e.png",
{
mediaOptions:
{
mimeType: 'image/png',
mediaType: 'image'
},
metadataOptions:
{
isPrivate: false,
isVisitorUpload: false
}
}
)
.then(async File => {
const fU = File?.fileUrl;
if (fU) {
const url = await mediaManager.getDownloadUrl(fU);
return url;
}
else
return "";
})
.catch((Error) => {
console.log(Error);
return "";
});
}
else
return null;
})
.catch((Error) => {
console.log(Error);
return null;
});