cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close

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: 
Highlighted

View a file using a authentication token

Explorer | Level 4

I have a general question.  Is it possible using the dropbox api to view a file using an authentication token rather than logging in?

I am creating a website that uses dropbox to store documents that are not for public viewing.  I dont want to enable link sharing (which I have done successfully already for something else) but i would like them to click a file and go and view it (using an athentication token that the server provides) rather than dowloading it (which ive also figured out).  

Ive had a look through the api but cant seem to find anything that fits the bill. 

Dropbox in node (pretty sure this is the official dropbox node api)

// UPLOAD CODE (working) //

import fetch from 'isomorphic-fetch';
import {Dropbox} from 'dropbox';
import {Meteor} from 'meteor/meteor';

import {
  FILE_UPLOAD,
  FILE_UPLOAD_ERROR,
  FILE_UPLOAD_SUCCESS,
} from '../../store/reducers/file/constants';

export default async function uploadFile(file, callback, data) {
  data.dispatch({type: FILE_UPLOAD, payload: true});
  Meteor.call('authDropbox', async function(error, result) {
    try {
      const dbx = new Dropbox({accessToken: result.token, fetch: fetch});
      const response = await dbx.filesUpload({
        contents: file, 
path: `/${data.location}/${file.name}`, mode: 'add', autorename: true, mute: true, }); callback(response, data); data.dispatch({type: FILE_UPLOAD_SUCCESS}); } catch (err) { data.dispatch({ type: FILE_UPLOAD_ERROR, payload: err.message, }); } }); }

 

 

// DOWNLOAD CODE (working) //

 

import fetch from 'isomorphic-fetch';
import {Dropbox} from 'dropbox';
import {Meteor} from 'meteor/meteor';
import {saveAs} from 'file-saver';

export default async function downloadFile(file) {
  Meteor.call('authDropbox', async function(error, result) {
    try {
      const dbx = new Dropbox({accessToken: result.token, fetch: fetch});
      const response = await dbx.filesDownload({path: file.path_display});
      saveAs(response.fileBlob, response.name);
    } catch (err) {
      console.log(err);
    }
  });
}

 

// CREATE SHARING LINK (working) //

//this should be inserted in the upload code while authorised
const response = await dbx.sharingCreateSharedLink({
    path: `/${data.location}/${file.name}`
});
const sharingLink = response.url;  
//store sharing link somewhere i generaly do it in the callback

 

1 Accepted Solution

Accepted Solutions
Highlighted

Re: View a file using a authentication token

Dropboxer
Dropboxer

Thanks for writing this up. The Dropbox API doesn't offer anything quite like what you describe, but I'll be happy to pass this along as a feature request.

To clarify a bit first though, do you mean that you would want the user to be able to go view the file on www.dropbox.com with the Dropbox file viewer web page like they would normally from the official Dropbox web site file listing, or do you just want a link that would return the file data directly, without the Dropbox file viewer web page?

View solution in original post

3 Replies 3
Highlighted

Re: View a file using a authentication token

Dropboxer
Dropboxer

Thanks for writing this up. The Dropbox API doesn't offer anything quite like what you describe, but I'll be happy to pass this along as a feature request.

To clarify a bit first though, do you mean that you would want the user to be able to go view the file on www.dropbox.com with the Dropbox file viewer web page like they would normally from the official Dropbox web site file listing, or do you just want a link that would return the file data directly, without the Dropbox file viewer web page?

View solution in original post

Highlighted

Re: View a file using a authentication token

Explorer | Level 4

Hello Greg

Yea.  Viewing it on the dropbox site is what I imagined.  Efectively a security layer between public and user login that uses credentails from a server rather than from the user. (A server request that generates a temporary link maybe?  Depends on how you want to handle it).

Thanks for the reply. For now ill just use the downloading function and ill keep an eye out for this as a feature for future projects.  

Highlighted

Re: View a file using a authentication token

Dropboxer
Dropboxer

Thanks for clarifying! I'm sending this along as a feature request, though I can't promise if or when that might be implemented.

Polls
Do you know how to organize your files and folders?
We have created a guide on folder best practice, so you can get organized now check it out here.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?