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);
?>