Example #1
0
def create():
    bucketName = request.form['bucketName']
    s3_resource = S3.get_resource()
    s3_resource.create_bucket(
        Bucket=bucketName,
        CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'})
    flash("Bucket Created Successfully!!")
    buckets = S3.get_buckets_list()
    return render_template("buckets/index.html", buckets=buckets)
Example #2
0
def delete(bucket):
    s3_resource = S3.get_resource()
    my_bucket = s3_resource.Bucket(bucket)
    if len(list(my_bucket.objects.all())) > 0:
        flash("Bucket Not Empty -- Cannot Be Deleted")
    else:
        flash("Bucket Sucessfully Deleted!")
        my_bucket.delete()
    buckets = S3.get_buckets_list()
    return render_template("buckets/index.html", buckets=buckets)
Example #3
0
def delete():
    key = request.form['key']
    s3_resource = S3.get_resource()
    my_bucket = s3_resource.Bucket(session.get('bucket'))
    my_bucket.Object(key).delete()
    flash('File deleted successfully')

    return redirect(
        url_for('files.files', bucket=session.get('bucket', 'DUMMY')))
Example #4
0
def files(bucket):
    if bucket == 'DUMMY':
        return render_template('files/files.html', my_bucket='', files='')
    session['bucket'] = bucket
    s3_resource = S3.get_resource()
    my_bucket = s3_resource.Bucket(bucket)
    summaries = my_bucket.objects.all()
    return render_template('files/files.html',
                           my_bucket=my_bucket,
                           files=summaries)
Example #5
0
def download():
    key = request.form['key']
    print('Download File Name ----> {}').format(key)
    s3_resource = S3.get_resource()
    my_bucket = s3_resource.Bucket(session.get('bucket'))

    file_obj = my_bucket.Object(key).get()

    return Response(
        file_obj['Body'].read(),
        mimetype='text/plain',
        headers={"Content-Disposition": "attachment;filename={}".format(key)})
Example #6
0
def create_app():
    app = Flask(__name__, instance_relative_config=True)
    Bootstrap(app)

    # Setup Jinja Filters to Map to Custom Python Functions
    # These functions will
    app.jinja_env.filters['Hdatetimeformat'] = date_timeformat
    app.jinja_env.filters['file_type'] = file_type

    # Register the Blueprints
    app.register_blueprint(buckets.bp)
    app.register_blueprint(files.bp)

    # First Get all the Keys From the Config File
    s3config = S3.get_config()
    app.secret_key = s3config.APP_SECRET_KEY

    return app
Example #7
0
def upload():
    try:
        file = request.files['filename']
    except KeyError:
        flash('No File Selected')
        return redirect(
            url_for('files.files', bucket=session.get('bucket', 'DUMMY')))
    except:
        flash('No File Selected')
        return redirect(
            url_for('files.files', bucket=session.get('bucket', 'DUMMY')))

    s3_resource = S3.get_resource()
    my_bucket = s3_resource.Bucket(session.get('bucket'))
    my_bucket.Object(file.filename).put(Body=file)
    flash('Files Uploaded Sucessfully')

    return redirect(
        url_for('files.files', bucket=session.get('bucket', 'DUMMY')))
Example #8
0
def index():
    session.clear()
    buckets = S3.get_buckets_list()
    return render_template("buckets/index.html", buckets=buckets)