Skip to main content

Add support of Dropbox API to the Flask applications.

Project description

Add support of Dropbox API to the Flask applications.

Requirements

Installation

$ pip install Flask-Dropbox

License

Flask-Dropbox is licensed under the BSD License.

Configuration

SECRET_KEY

REQUIRED. As token would be stored in Flask’s session instance, you need to configure secret key for your application.

DROPBOX_KEY

REQUIRED. App key from Dropbox developer site.

DROPBOX_SECRET

REQUIRED. Secret key from Dropbox developer site.

DROPBOX_ACCESS_TYPE

REQUIRED. Should be 'dropbox' or 'app_folder' as configured for your app.

DROPBOX_CALLBACK_URL

By default, you don’t need to provide this setting, cause Flask-Dropbox will setup callback URL automaticly usign current host and type of request, but if you don’t trust us, you could to rewrite this setting manually.

DROPBOX_CALLBACK_TEMPLATE

Template to be used for showing errors while trying to process oAuth callback from Dropbox API. By default: 'dropbox/callback.html'.

Next boolean vars could be sent to the template:

  • error_oauth_token - Dropbox API didn’t return oAuth token.

  • error_not_equal_tokens - oAuth token from Dropbox API is not equal to request token stored in Flask session.

  • error_response - Dropbox API returns ErrorResponse instance. Also actual exception as error var would be sent to the template too.

DROPBOX_LOGIN_REDIRECT

Page to redirect to after user successfully logged in with Dropbox account. By default: /.

DROPBOX_LOGOUT_REDIRECT

Page to redirect to after user logged out from authenticated Dropbox session. By default: /.

Usage

app.py:

from flask import Flask
from flask.ext.dropbox import Dropbox, DropboxBlueprint

import settings


app = Flask(__name__)
app.config.from_object(settings)

dropbox = Dropbox(app)
dropbox_blueprint = DropboxBlueprint(dropbox)
app.register_blueprint(dropbox_blueprint, url_prefix='/dropbox')

settings.py:

SECRET_KEY = 'some-secret-key'
DROPBOX_KEY = 'dropbox-app-key'
DROPBOX_SECRET = 'dropbox-app-secret'
DROPBOX_ACCESS_TYPE = 'app_folder'

views.py:

from flask import url_for
from werkzeug import secure_filename

from app import app, dropbox


@app.route('/')
def home():
    return u'Click <a href="%s">here</a> to login with Dropbox.' % \
           dropbox.login_url


@app.route('/success/<path:filename>')
def success(filename):
    return u'File successfully uploaded as /%s' % filename


@app.route('/upload', methods=('GET', 'POST'))
def upload():
    if not dropbox.is_authenticated:
        return redirect(url_for('home'))

    if request.method == 'POST':
        file_obj = request.files['file']

        if file_obj:
            client = dropbox.client
            filename = secure_filename(file.filename)

            # Actual uploading process
            result = client.put_file('/' + filename, file_obj.read())

            path = result['path'].lstrip('/')
            return redirect(url_for('success', filename=path))

    return u'<form action="" method="post">' \
           u'<input name="file" type="file">' \
           u'<input type="submit" value="Upload">' \
           u'</form>'

Bugs, feature requests?

If you found some bug in Flask-Dropbox library, please, add new issue to the project’s GitHub issues.

ChangeLog

0.1.2

  • Add support of Dropbox SDK 1.4.1

0.1.1

  • Check that access token is the instance of oauth.OAuthToken class if it exists in session.

0.1

  • Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-Dropbox-0.1.2.tar.gz (6.8 kB view details)

Uploaded Source

File details

Details for the file Flask-Dropbox-0.1.2.tar.gz.

File metadata

File hashes

Hashes for Flask-Dropbox-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ba6929b5f98762cf247d5e5411acbe89f8d2229d2ecfb542c03065fd2a6cabcd
MD5 d3a80b642eb883515e894a9722ae2c23
BLAKE2b-256 fab152877d33eb935c738fdf82197407154f6ac648531c130383d8d55f3a3544

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page