Beispiel #1
0
def files():
    s3_resource = boto3.resource('s3')
    my_bucket = s3_resource.Bucket('remade-nde')
    summaries = my_bucket.objects.all()

    form = UploadForm()

    if form.is_submitted():
        info = {
            'nde': form.nde.data,
            'exp_id': form.exp_id.data,
            'loading_amp': form.loading_amp.data,
            'percent_fatigue_life': form.percent_fatigue_life.data,
            'nlu_amp': form.nlu_amp.data,
            'dist_from_center': form.dist_from_center.data
        }

        filename = naming_file(info)

        file = request.files['file']
        s3_resource = boto3.resource('s3')
        my_bucket = s3_resource.Bucket('remade-nde')
        my_bucket.Object(filename).put(Body=file)
        data = my_bucket.Object(filename).get()['Body']

        flash('File uploaded successfully')
        return redirect(url_for('files'))

    return render_template('files.html',
                           my_bucket=my_bucket,
                           files=summaries,
                           form=form)
Beispiel #2
0
def upload():
    if not session.get('logged_in'):
        abort(401)

    # Instantiate your form class

    if request.method == 'POST':
        form = UploadForm()
        if form.is_submitted() and form.photo.data:
            if not image_file.match(form.photo.data.filename):
                return render_template('upload.html', form=UploadForm(), error=True)
            photo = form.photo.data
            filename = secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOADED_IMAGES_DEST'], filename))

            flash('File Saved', 'success')
            return redirect(url_for('home'))

    return render_template('upload.html', form=UploadForm(), error=False)