Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

389
Visualizações
Fetching an image (Node.js)

I am trying to fetch the image from https://api-assets.clashroyale.com/cards/300/CoZdp5PpsTH858l212lAMeJxVJ0zxv9V-f5xC8Bvj5g.png The code to fetch:

fetch('https://api-assets.clashroyale.com/cards/300/CoZdp5PpsTH858l212lAMeJxVJ0zxv9V-f5xC8Bvj5g.png', )
                .then(res => res.blob())
                .then(myBlob => URL.createObjectURL(myBlob));

The error:

node:internal/errors:464
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "obj" argument must be an instance of Blob. Received an instance of Blob
    at new NodeError (node:internal/errors:371:5)
    at Function.createObjectURL (node:internal/url:960:13)
    at C:\Users\lars\OneDrive - CVO-AV\Documenten\GuideBot\src\Commands\clash.js:45:37
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}

node version: v16.13.1

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I found out that node-fetch doesnt support .blob() yet, so instead you will need to do it like the example in npm:

const { pipeline } = require('node:stream');
const { promisify } = require('node:util');
const { createWriteStream } = require('node:fs');

const streamPipeline = promisify(pipeline)

const response = await fetch('https://api-assets.clashroyale.com/cards/300/CoZdp5PpsTH858l212lAMeJxVJ0zxv9V-f5xC8Bvj5g.png');
await streamPipeline(response.body, createWriteStream('./octocat.png'))

Wich returns the image correctly: https://cdn.discordapp.com/attachments/950681875733708820/967324291161010216/unknown.png

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda