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

223
Visualizações
Why my Imgur API in Javascript doesn't work?

I need to upload my image in imgur with imgur's API, and i do that in Javascript but i have all time a response like "429 - Too many request" or "403 - Imgur is temporarily over capacity. Please try again later". And I also do a API test in PHP but with this i have no problem

I need help to understand why my call API in JS doesn't work

(the file in my function JS come to HTML tag input file multiple)

My JS code

function FolderAddPictureUploadImgur(file) {
    var imgur_client_id = "xxxx";
    
    const formData = new FormData();
    formData.append('image', file);
    
    fetch('https://api.imgur.com/3/image', {
        method: 'POST',
        headers: {
        Authorization: 'Client-ID '+ imgur_client_id,
        },
        body: formData
    }).then(response => {
        console.log(response);
        if (response.ok) {
        alert('Image uploaded to album');       
        }
    }).catch(error => {
        console.error(error);
        //alert('Upload failed: ' + error);
    });
}

My code PHP

<?php
$imgur_client_id = 'xxx';

$file = file_get_contents("test_image.png");

$url = 'https://api.imgur.com/3/image.json';
$headers = array("Authorization: Client-ID $imgur_client_id");
$pvars  = array('image' => base64_encode($file));

$curl = curl_init();
curl_setopt_array($curl, array(
   CURLOPT_URL=> $url,
   CURLOPT_TIMEOUT => 30,
   CURLOPT_POST => 1,
   CURLOPT_RETURNTRANSFER => 1,
   CURLOPT_HTTPHEADER => $headers,
   CURLOPT_POSTFIELDS => $pvars
));

$json_returned = curl_exec($curl); // blank response
echo($json_returned);

$json_returned = json_decode($json_returned, true);

curl_close ($curl); 

?>
about 4 years ago · Juan Pablo Isaza
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