2

I have a react app where I upload images to imgur like:

  const formData = new FormData();
  formData.append('image', file);
  return fetch('https://api.imgur.com/3/image/', {
    method: 'POST',
    headers: { Authorization: 'Client-ID xxxxxxxxxxxxx' },
    body: formData,
  })

I used to be able to upload images from my localhost, but now when I run the same code I get:

Access to fetch at 'https://api.imgur.com/3/image/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

So does this mean imgur updated their CORS policy?

abc
  • 1,141
  • 12
  • 29

1 Answers1

0

Imgur's API does not allow localhost for some reason, but it does allow other addresses. If you add an entry to /etc/hosts (unix) or with dnscmd (windows) that points to localhost, it will work fine from that address

127.0.0.1 imgurtesting
dnscmd /RecordAdd imgurtesting * 3600 A 127.0.0.1

The api will work from http://imgurtesting:…/… in your browser.

pfg
  • 2,348
  • 1
  • 16
  • 37