We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Alex-Mason-1982
7 years agoExplorer | Level 4
View a file using a authentication token
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
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?
3 Replies
- Greg-DB7 years ago
Dropbox Community Moderator
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?
- Alex-Mason-19827 years agoExplorer | 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.
- Greg-DB7 years ago
Dropbox Community Moderator
Thanks for clarifying! I'm sending this along as a feature request, though I can't promise if or when that might be implemented.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!