9

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.

keydo
  • 93
  • 4
  • Possible duplicate of [No 'Access-Control-Allow-Origin' header is present on the requested resource error](https://stackoverflow.com/questions/28547288/no-access-control-allow-origin-header-is-present-on-the-requested-resource-err) – FreedomPride Oct 04 '17 at 03:43
  • Possible duplicate of [CORS issues with jQuery Dropzone and upload to Imgur](https://stackoverflow.com/questions/25427627/cors-issues-with-jquery-dropzone-and-upload-to-imgur) – Ken Y-N Oct 04 '17 at 03:47
  • 3
    I've the same problem. only came up today. Is there something wrong with the API? – Programmer Oct 04 '17 at 06:05
  • @Programmer It seems: for me the imgur API is returning the "access-control-allow-origin" header empty. Seems no one posted this issue [here](https://community.imgur.com/c/meta). Someone here already [contacted support](https://help.imgur.com/hc/en-us/requests/new)? – Gustavo Rodrigues Oct 04 '17 at 15:13
  • @GustavoRodrigues I just send an email to support. – keydo Oct 04 '17 at 15:48
  • Same problem here, was working good, came up today! I already contact support but i'm still waiting for **a response** – GeorgeMR Oct 05 '17 at 03:02
  • 1
    Now it's working for me: seems the issue was fixed. – Gustavo Rodrigues Oct 05 '17 at 22:58
  • @GustavoRodrigues Yea its working on my side now too. – Programmer Oct 06 '17 at 07:28

2 Answers2

1

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: *

jamesinc
  • 493
  • 4
  • 11
0

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

keydo
  • 93
  • 4
  • It's not fixed. Still cannot register application: https://api.imgur.com/oauth2/addclient ... that redirects elsewhere. – Hayden Oct 07 '17 at 23:31