Exemplo n.º 1
0
def handle_request():
    if request.method == 'POST':
        if request.files:
            username = '******'

            filename = images.save(request.files['image'])
            url = images.url(filename)

            #---------------------

            result = predict(filename)

            #---------------------

            user = User.query.filter_by(username=username).first()
            if user is None: user = User(username=username)

            report = Report(user=user, data=json.dumps(result))

            image = Image(report=report)

            image.image_filename = filename
            image.image_url = url

            db.session.add(user)
            db.session.add(report)
            db.session.add(image)

            db.session.commit()

            return 'Report Generated'
        return 'No Files Recieved'
    return 'Method not POST'
Exemplo n.º 2
0
def upload():
    form = UploadForm()
    if request.method == 'POST':
        if form.validate_on_submit():

            username = form.username.data

            filename = images.save(request.files['image'])
            url = images.url(filename)

            #---------------------

            result = predict(filename)

            #---------------------

            user = User.query.filter_by(username=username).first()
            if user is None: user = User(username=username)

            report = Report(user=user, data=json.dumps(result))

            image = Image(report=report)

            image.image_filename = filename
            image.image_url = url

            db.session.add(user)
            db.session.add(report)
            db.session.add(image)

            db.session.commit()

            flash(
                'User Report for username: {} generated. '.format(
                    form.username.data), 'success')
            return redirect(url_for('report', report_id=report.id))
        else:
            flash_errors(form)
            flash('ERROR! Report was not generated.', 'error')

    return render_template('upload.html', title='Upload', form=form)
Exemplo n.º 3
0
def upload_images():

    images = {}
    idx = 0
    if len(request.files) > 0:
        file_list = request.files.getlist('images')
        for file in file_list:
            if not check_file(file.filename):
                return {'errors': ['Unaccepted file extension, must be JPG, PNG, or JPEG']}, 400
        for file in file_list:
            image = Image()
            image.user_id=current_user.id
            image.type_id=request.form.get("type_id")
            image.type=request.form.get("type")
            file_url = upload_file_to_s3(file, Config.S3_BUCKET)
            image.image_url = file_url
            db.session.add(image)
            db.session.commit()
            images[idx] = image.to_dict()
            idx += 1
            
        return images, 201
    else:
        return {"errors":"no files"}, 400