cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We've been busy working on some major updates to the Community, so check out what's changing, what’s staying the same and what you can expect from the Dropbox Community right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '

The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*'

hayk
Explorer | Level 4
Go to solution

Hey guys I am using npm package to work with dropbox. However when I try to upload a file I get the following error

 

XMLHttpRequest cannot load https://content.dropboxapi.com/2/files/upload. Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:3000' is therefore not allowed access. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

 

Any idea why is this happening and what can I do about this?

Thank you.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

 

I used an example Meteor app, and in server/main.js I just used the node library normally:

 

var Dropbox = require('dropbox');

 

    const dbx = new Dropbox({accessToken: "<ACCESS_TOKEN>"})
    dbx.filesUpload({path: "/test_207235.txt", contents: "some test data"})
      .then(function (response) {
        console.log(response)
      })
      .catch(function (error) {
        console.error(error)
      })

That uploaded the file successfully. Attempting the same in client/main.js failed with the same error you got.

 

I don't have a more advanced sample available though. The filesUpload method takes a string or buffer, but beyond that I'm afraid I can't offer much insight as to how to manage files/data in node and Meteor themselves.

 

If you want to upload directly from the user's browser, you can use the JavaScript SDK in the browser's JavaScript. E.g., include the library via a script tag in your HTML, and run JavaScript from a script tag, as shown in the basic browser example.

 

View solution in original post

6 Replies 6

Greg-DB
Dropbox Staff
Go to solution
Thanks for the post. We'll be happy to help with this. Can you let me know what version of the library you're using, and share the code that reproduces this issue? Thanks in advance!

hayk
Explorer | Level 4
Go to solution

Hi Greg!

I'm using dropbox@2.5.1

 

And here is the code

 

import Dropbox from 'dropbox'

uploadCallback (file,self) {
    // TODO: Integrate dropbox with its SDK
    // TODO: Pass the link to the editor
    // const self = this
    console.log(self)
    return new Promise(
      (resolve, reject) => {
        console.log('uploadCallback promise')
        console.log('file', file)
        const dataObject = {
          file,
          resolve,
          reject
        }
        console.log('dataObject', dataObject)
        self.uploadToDropbox(dataObject)
      }
    )
  }

uploadToDropbox (dataObject) {
    const dbx = new Dropbox({accessToken: Meteor.settings.public.dropbox.accessToken})
    console.log('dataObject', dataObject)
    const { file } = dataObject
    console.log('file', file)
    const { resolve, reject } = dataObject
    console.log('resolve', resolve)
    console.log('reject', reject)
    dbx.filesUpload({path: '/' + file.name, contents: file})
      .then(function (response) {
        console.log(response)
        resolve({ data: { link: 'http://dummy_image_src.com' } })
      })
      .catch(function (error) {
        console.error(error)
        reject('some error')
      })
    return false
  }

Do you have any ideas?

Greg-DB
Dropbox Staff
Go to solution

Thanks! Based on your code, it looks like you're running this in a Meteor app.

 

I tried it out in a Meteor app, and I wasn't able to reproduce the issue when making an upload code in the 'server' code, but I was when I tried to run it in the 'client' code. Are you running this in the client code?

 

I'm not sure offhand if this is something we can support, so instead you can either:

- run this in your 'server' code.
- import the JavaScript SDK as a JavaScript library on the page and use the normal browser interface.

hayk
Explorer | Level 4
Go to solution

Hi Greg!

Thanks for your reply and you got it all right!

Would you mind if I ask how you used the sdk in the server?

You see at first I tried using it in the server however I got problems passing the file object to a Meteor method in the server. Then I convereted the file to base64 send it to the server and was able to upload to dropbox, however the image was empty. So I thought the problem may be while passing file from client to server thus it would be better to directly upload to dropbox from the client. And then I got this headers' error. But I am pretty much sure I am overcomplicating something and there is a simpler solution.

Greg-DB
Dropbox Staff
Go to solution

 

I used an example Meteor app, and in server/main.js I just used the node library normally:

 

var Dropbox = require('dropbox');

 

    const dbx = new Dropbox({accessToken: "<ACCESS_TOKEN>"})
    dbx.filesUpload({path: "/test_207235.txt", contents: "some test data"})
      .then(function (response) {
        console.log(response)
      })
      .catch(function (error) {
        console.error(error)
      })

That uploaded the file successfully. Attempting the same in client/main.js failed with the same error you got.

 

I don't have a more advanced sample available though. The filesUpload method takes a string or buffer, but beyond that I'm afraid I can't offer much insight as to how to manage files/data in node and Meteor themselves.

 

If you want to upload directly from the user's browser, you can use the JavaScript SDK in the browser's JavaScript. E.g., include the library via a script tag in your HTML, and run JavaScript from a script tag, as shown in the basic browser example.

 

hayk
Explorer | Level 4
Go to solution

Hi dear Greg,

I found the way to upload my file. The problem was in the way I was creating the buffer. So now I am able to upload from my server. I'm putting a gist here in case anyone will need it.

https://gist.github.com/hayk94/2a11702a3476f49bd65e36e7fa715d90

Though now I need to get a link of the image to show it in my HTML and there seems to be no way to do that programmatically, but I think that is another story therefore I created a new topic https://www.dropboxforum.com/t5/API-support/Share-and-get-the-link-via-api/m-p/208116#M10220

Need more support?