Beispiel #1
0
def index():
    if request.method == 'POST':
        uploaded_file = request.files['file']
        w = request.form.get('w')
        h = request.form.get('h')
        if not uploaded_file:
            return abort(400)  # Bad Request

        # TODO: unique constraint failed
        if w and h:
            uploaded_file = UploadedFile.resize(uploaded_file, w, h)
        else:
            uploaded_file = UploadedFile.create_by_uploaded_file(uploaded_file)
        uploaded_file.save()

        return jsonify(
            {
                'url_d': uploaded_file.url_d,
                'url_i': uploaded_file.url_i,
                'url_s': uploaded_file.url_s,
                'url_p': uploaded_file.url_p,
                'filename': uploaded_file.filename,
                'size': humanize_bytes(uploaded_file.size),
                'time': str(uploaded_file.uploaded_time),
                'type': uploaded_file.type,
                'quoteurl': uploaded_file.quoteurl,
            }
        )

    return render_template('index.html', **locals())
Beispiel #2
0
def resize(img_hash):
    w = request.args.get('w')
    h = request.args.get('h')

    if w and h:
        old_file = UploadedFile.objects.get_or_404(filehash=img_hash)
        new_file = UploadedFile.resize(old_file, w, h)
        return new_file.url_i