Beispiel #1
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')))
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #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)})
Beispiel #6
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')))