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