Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imgur API Failed to load [closed]

Tags:

jquery

api

imgur

I get this in the console:

Failed to load https://api.imgur.com/3/image: The 'Access-Control-Allow-Origin' header contains the invalid value ''. Origin 'https://example.org' is therefore not allowed access.

and this is my code:

            var formData = new FormData();
            formData.append('image', $('#imgur-api-upload')[0].files[0]);
            formData.append('type', 'file');
            formData.append('name', $('#imgur-api-upload')[0].files[0].name.replace('.jpg', ''));
            // request
            $.ajax({
                async: true,
                crossDomain: true,
                url: 'https://api.imgur.com/3/image',
                method: 'POST',
                headers: {
                    'Authorization': 'Bearer ' + imgur_access_token
                },
                processData: false,
            contentType: false,
            mimeType: 'multipart/form-data',
            data: formData
            })
            .done(function(dataResponse) {
                console.log(dataResponse);
                if (dataResponse.hasOwnProperty('status') && dataResponse.hasOwnProperty('success')) {
                    if (dataResponse['success'] == true && dataResponse['status'] == 200) {
                        $('#episode_image').val(dataResponse['data']['link']);
                    } else {
                        alert('Error: ' + dataResponse['data']['error']);
                    }
                }
            })

I tried to upload images anonymously, but got the same error. This are the Response Headers:

access-control-allow-credentials:true
access-control-allow-headers:Authorization, Content-Type, Accept, X-Mashape-Authorization, IMGURPLATFORM, IMGURUIDJAFO, SESSIONCOUNT, IMGURMWBETA, IMGURMWBETAOPTIN
access-control-allow-methods:GET, PUT, POST, DELETE, OPTIONS
access-control-allow-origin:
access-control-expose-headers:X-RateLimit-ClientLimit, X-RateLimit-ClientRemaining, X-RateLimit-UserLimit, X-RateLimit-UserRemaining, X-RateLimit-UserReset
cache-control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
content-encoding:gzip
content-length:330
content-type:application/json
date:Wed, 04 Oct 2017 03:25:41 GMT

But in the response tab I see the json, but seems that can't access to it.

I tried to add Header set Access-Control-Allow-Origin * in the .htaccess of wordpress but didn't work.

EDIT:
The "possible duplicate" answers don't solve my problem, already tried the examples (before publishing the question) in localhost / example.dev, live website, Chrome/Firefox/Edge, diferent pc on diferent network but still get empty access-control-allow-origin.

EDIT2:
API Support Team: This issue was caused by a misconfiguration and should now be resolved.

like image 693
keydo Avatar asked Oct 04 '17 03:10

keydo


1 Answers

I'm having this issue since yesterday too. The issue seems to be that a blank Access-Control-Allow-Origin header value is considered invalid by the browser. Maybe this is a regression in the API? The preflight response correctly has Access-Control-Allow-Origin: *

like image 77
jamesinc Avatar answered Sep 21 '22 19:09

jamesinc