Announcements
Do you have an idea for Dropbox Paper? Share it with us!

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

Re: View a file using a authentication token

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?

Reply
Loading...
3 Replies

Re: View a file using a authentication token

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?

Reply
Loading...

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.  

Reply
Loading...

Re: View a file using a authentication token

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.

Reply
Loading...
API Support

Have a question? Our Dropbox Community is here to help you find an answer!
You won’t have to wait too long for a reply, but why not learn more about the Community while you’re here.

Not the right discussion for you? Find out what else our Community has to say about API Support.

Or, search our Help Center for even more.

Who's talking
Top contributors to this post