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: 

View a file using a authentication token

View a file using a authentication token

Alex-Mason-1982
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

Greg-DB
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

Re: View a file using a authentication token

Greg-DB
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

Re: View a file using a authentication token

Alex-Mason-1982
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.  

Re: View a file using a authentication token

Greg-DB
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.

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

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