Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
dropbox-apix
Advanced tools
Dropbox-APIx is Dropbox API wrapper with simple upload and share options. It should be used in applications on server side for easy upload on Dropbox and automatic share it. Using this wrapper in MeteorJS framework is also supported.
A simple explanation will be: Call upload method with some parameters and content of a file, it will upload a file and return shared link which could be stored somewhere (in database). For detailed explanation, please read bellow.
Before start to use this Dropbox API wrapper, please create your Dropbox account and get API key. Please visit https://www.dropbox.com/developers. Also this or this video should help to generate API key.
Install npm package with: npm install 'dropbox-apix' --save
or install in MeteorJS app folder with: meteor npm install 'dropbox-apix' --save
.
These dependencies are used in wrapper:
* Note: Dependencies will be automatically installed while installing this wrapper
Node JS example on server side:
var DropboxApix = require('../dropbox-apix');
var fs = require('fs'); // We need this for file reading
var dbx = new DropboxApix({
key: 'DROPBOX API KEY'
});
var params = {
path: '/name-of-uploaded-file.jpg',
autorename: true
}
fs.readFile('local-file-on-server.jpg', function(err, contents) {
let buffer = new Buffer(contents);
dbx.upload_with_sharing(params, buffer, function(res, err) {
if(err) {
console.log(err.msg);
return;
};
console.log(res); // res is json with filename and link properties
});
});
In callback function, res
contains:
{
filename: <filename on server>,
link: <direct link which should be used in HTML -> A HREF property>
}
MeteorJS example:
// server side
import DropboxApix from 'dropbox-apix';
if(Meteor.isServer) {
dbx = new DropboxApix({
key: 'DROPBOX API KEY'
});
}
Meteor.methods({
'file-upload': function (filename, fileData) {
var params = {
path: '/'+filename,
autorename: true
}
dbx.upload_with_sharing(params, new Buffer(fileData), function(res, err) {
if(err) {
console.log(err.msg);
return;
};
// res.link should be stored in database or somewhere else
console.log(res);
});
}
});
// client side
//HTML
<template name="uploadForm">
<input id="fileInput" type="file" />
</template>
//JS
Template.uploadForm.events({
'change #fileInput'(e, template) {
if (e.currentTarget.files && e.currentTarget.files[0]) {
var file = e.currentTarget.files[0];
var filename = file.name;
var reader = new FileReader();
reader.onload = function(fileLoadEvent) {
var buffer = new Uint8Array(reader.result) // convert to binary
Meteor.call('file-upload', filename, buffer);
};
reader.readAsArrayBuffer(file);
}
}
});
After file is uploaded and link received on server side, it should be stored in Database. Client should be subscribed to the collection where are stored links of uploaded files.
var dbx = new DropboxApix({
key: 'DROPBOX API KEY'
});
Debug is turned off by default. To use debug, add it to the constructor.
var dbx = new DropboxApix({
key: 'DROPBOX API KEY',
debug: true
});
Debug will print all actions in servers console.
This method creates folder on Dropbox.
var params = {
"path": "/custom-folder-name",
"autorename": false
}
dbx.create_folder(params, function(res, err) {
if(err) {
console.log(err.msg);
return;
};
console.log(res);
});
Create folder method will return JSON with properties:
{
name: 'custom-folder-name',
path_lower: '/custom-folder-name',
path_display: '/custom-folder-name',
id: 'id:123456xyz'
}
There is a possibility to use sub folder while uploading (if folder does not exist, will be created automatically):
var params = {
path: '/custom-folder-name/name-of-uploaded-file.jpg',
autorename: true
}
Upload method uploads file on Dropbox without sharing option.
var params = {
path: '/name-of-uploaded-file.jpg',
autorename: true
}
fs.readFile('test.jpg', function(err, contents) {
let buffer = new Buffer(contents);
dbx.upload(params, buffer, function(res, err) {
if(err) {
console.log(err.msg);
return;
};
console.log(res);
});
});
res
contains:
{
name: 'name-of-uploaded-file.jpg',
path_lower: '/name-of-uploaded-file.jpg',
path_display: '/name-of-uploaded-file.jpg',
id: 'id:123456xyz',
client_modified: '2018-10-06T22:03:54Z',
server_modified: '2018-10-06T22:03:54Z',
rev: 'xyz123',
size: 123456,
content_hash: '123456abcdef'
}
Upload with sharing method uploads file on Dropbox and automatically shares is.
var params = {
path: '/name-of-uploaded-file.jpg',
autorename: true
}
fs.readFile('local-file-on-server.jpg', function(err, contents) {
let buffer = new Buffer(contents);
dbx.upload_with_sharing(params, buffer, function(res, err) {
if(err) {
console.log(err.msg);
return;
};
console.log(res); // res is json with filename and link properties
});
});
res
contains:
{
filename: <filename on server>,
link: <direct link which should be used in HTML -> A HREF property>
}
Generate shared link method generate shared link if does not exist. If it exist, just return it.
var params = {
"path": "/already-uploaded-file.jpg"
}
dbx.generate_shared_link('already-uploaded-file.jpg', function(res, err) {
if(err) {
console.log(err.msg);
return;
};
console.log(res);
});
res
contains:
{
filename: <filename on server>,
link: <direct link which should be used in HTML -> A HREF property>
}
MIT
dropbox dropbox-api dropbox-wrapper meteor meteor-api webstorage storage
FAQs
Dropbox API wrapper
The npm package dropbox-apix receives a total of 2 weekly downloads. As such, dropbox-apix popularity was classified as not popular.
We found that dropbox-apix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.