cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done 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: 

NetworkError when attempting to fetch resource when trying to share file using javascript sdk

NetworkError when attempting to fetch resource when trying to share file using javascript sdk

ER2480
Explorer | Level 4

Hi,

I am very new to the Dropbox SDK, I am trying to programmatically create a link for sharing a file and getting the above error:

NetworkError when attempting to fetch resource when trying to share file using javascript sdk

I am using the following code:

var dbx = new Dropbox.Dropbox({ accessToken: ACCESS_TOKEN });
dbx.sharingCreateSharedLinkWithSettings({path: '/Filename.doc'})
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});

and in the same page I have a file uploaded that works fine. Any ideas?

Thank you

1 Accepted Solution

Accepted Solutions

Re: NetworkError when attempting to fetch resource when trying to share file using javascript sdk

Greg-DB
Dropboxer

Thanks! It looks like the issue here is that when you click "Share File", that causes the page itself to reload (since you're submitting a form), which interrupts the Dropbox API call. 

 

You should update or restructure your page to avoid that reload. That's not really related to the Dropbox API itself, but it looks like this StackOverflow post may be relevant.

View solution in original post

7 Replies 7

Re: NetworkError when attempting to fetch resource when trying to share file using javascript sdk

Greg-DB
Dropboxer

This code looks correct and works for me. I'll be happy to help with this however possible, but I could use some more information:

 

  • Is that the full error output you receive? Please share any other output. 
  • What version of the SDK are you using?
  • How are you importing the SDK?
  • What environment are you running this in? (Browser or node, and what version, for instance.)
  • Is there anything on your network connection that may be interfering with connections to api.dropboxapi.com?

Re: NetworkError when attempting to fetch resource when trying to share file using javascript sdk

ER2480
Explorer | Level 4

Hi, here are some more details about the error:

  • Is that the full error output you receive? Please share any other output. 
TypeError: Failed to fetch
Dropbox-sdk.min.js:1 Fetch failed loading: POST "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings".
  (anonymous) @ Dropbox-sdk.min.js:1   Promise.then (async)       value @ Dropbox-sdk.min.js:1   value @ Dropbox-sdk.min.js:1   h.sharingCreateSharedLinkWithSettings @ Dropbox-sdk.min.js:1   shareFile @ testDropbox.php:155   onsubmit @ testDropbox.php:36
Navigated to http://......
testDropbox.php:160 DropboxResponseError: Response failed with a 409 code at https://unpkg.com/dropbox/dist/Dropbox-sdk.min.js:1:30363
Dropbox-sdk.min.js:1 Fetch failed loading: POST "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings".
Navigated to http://..........
 
  • What version of the SDK are you using?
  • How are you importing the SDK?
 
 
  • What environment are you running this in? (Browser or node, and what version, for instance.)
  • Firefox/Chrome/Safari similar errors everywhere --> local website  using php and javascript
  • Is there anything on your network connection that may be interfering with connections to api.dropboxapi.com?

I don't think so because I successfully implemented the file upload using js and the file browser for the same account and using the same token so the connection should be fine.

 

 
 
 
 
 
 

Re: NetworkError when attempting to fetch resource when trying to share file using javascript sdk

Greg-DB
Dropboxer

Thanks! That's helpful. From this output, I see you are getting an API error (with a 409 status code).

 

You can print out the API error object like to see the endpoint-specific error:

        .catch(function(error) {
            console.log(error.error);
        });

 

Re: NetworkError when attempting to fetch resource when trying to share file using javascript sdk

ER2480
Explorer | Level 4

Thank you so much for the suggestion. I tried it but it returns .."undefined". 

Am I using the correct sdk version?

Re: NetworkError when attempting to fetch resource when trying to share file using javascript sdk

Greg-DB
Dropboxer

From your script tag, you're using the latest version, which should work. (Though for reference, in a production app we recommend you import a specific version, since the SDK may occasionally receive major updates with breaking changes.)

 

I can't seem to reproduce the "undefined" issue you're seeing though. Would you be able to share a live sample page showing the issue?

Re: NetworkError when attempting to fetch resource when trying to share file using javascript sdk

ER2480
Explorer | Level 4

Yes, here is a temporary file on a beta site

https://cdfbeta.creativedecisions.net/_admin/testDropbox.php?

Re: NetworkError when attempting to fetch resource when trying to share file using javascript sdk

Greg-DB
Dropboxer

Thanks! It looks like the issue here is that when you click "Share File", that causes the page itself to reload (since you're submitting a form), which interrupts the Dropbox API call. 

 

You should update or restructure your page to avoid that reload. That's not really related to the Dropbox API itself, but it looks like this StackOverflow post may be relevant.

View solution in original post

Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    ER2480 Explorer | Level 4
What do Dropbox user levels mean?
Need more support?