Search code examples
reactjsnosqlxmlhttprequestrestdb

post image to restdb gives Cross-Origin Request Blocked


I'm trying to post an image to restdb media archive, I followed the instructions on their website https://restdb.io/blog/a-picture-is-worth-a-1000-lines-of-code

but all I get is a error enter image description here

here is my code:

async function fetchPost(url, data) {
    let answer
    try {
      const response = await fetch(url, {
        method: 'post', // *GET, POST, PUT, DELETE, etc.
        headers: {
          'content-type': false,
          'x-apikey': '62050e461b941c73ff397a3f',
        },
        processData: 'false',
        body: data,
      })
      answer = await response.json()
    } catch (err) {
      console.log(err)
    } finally {
      return answer
    }
  }

let formData = new FormData()
formData.append('myFile', e.target.files[0], e.target.files[0].name)
    
fetchPost('https://mikey-f985.restdb.io/media', formData)

And Here is my API key (CORS) enter image description here


Solution

  • Just in case you are on the free plan: I had the same issue with GET requests, so i asked restdb directly for help and they answered: "Yes you can store images for use in development. But to serve them public you need a paid account."