1

I am trying to build a Chrome Extension that uses the BOX api.

I am able to authentificate and enable access for the app, and then I extract and store the access token from the URL.

The next step would be to upload a file to box, and I am trying to use the code they provided on the website with small modifications:

//file - a csv file I created before

var uploadUrl = 'https://upload.box.com/api/2.0/files/General';

// The Box OAuth 2 Header. Add your access token.
var headers = {
    Authorization: 'Bearer '+localStorage.authorization_token
};

$.ajax({
    url: uploadUrl,
    headers: headers,
    type: 'POST',
    // This prevents JQuery from trying to append the form as a querystring
    processData: false,
    contentType: false,
    data: link
}).complete(function ( data ) {
    // Log the JSON response to prove this worked
    console.log(data.responseText);
});

But upon running the code it gives me the following error:

405 (Method Not Allowed)

POST https://upload.box.com/api/2.0/files/General 405 (Method Not Allowed)k.cors.a.crossDomain.send @ jquery.js:4n.extend.ajax @ jquery.js:4downloadCSV @ content.js:351(anonymous function) @ content.js:276 content.js:361

NOTE: I contacted api@box.com and they said they enabled CORS for my account

In my manifest.json I have "permissions": ["tabs", "<all_urls>","storage" , "alarms" ]

Marc Zaharescu
  • 629
  • 1
  • 13
  • 34
  • It seems to be saying that POST is not allowed to that URL (which has nothing to do with CORS, POST appears to be forbidden entirely) but check the Net tab of your developer tool to make sure it is failing on POST and not OPTIONS. – Quentin Nov 16 '15 at 10:41
  • From the network tab, this is the only error displayed:`General 405 xhr jquery.js:4 202 B 192 ms` – Marc Zaharescu Nov 16 '15 at 10:50
  • Look at the Method column. Is that a POST or an OPTIONS? If you can't see a Method column, right click on the columns and pick Method so it gets displayed. – Quentin Nov 16 '15 at 10:51
  • The value in the method column is POST – Marc Zaharescu Nov 16 '15 at 10:56
  • OK, that then means that you can't make POST requests to that URL. This has absolutely nothing to do with CORS. – Quentin Nov 16 '15 at 10:57
  • Hmm I see so the actual problem is this URL https://upload.box.com/api/2.0/files/General – Marc Zaharescu Nov 16 '15 at 10:58
  • Well in this case what url should I use for box upload :(. Because I used the same application for dropbox and it was working fine. In dropbox if the folder u are trying to use is not existent, it will create it automatically – Marc Zaharescu Nov 16 '15 at 11:01

0 Answers0