def upload_single_picture(): file = request.files.getlist('upload')[0] base_number = database.db.session.query(database.Image).count() + 1 mimetype = file.mimetype if file and allowed_mimetype(mimetype): original_filename = file.filename extension = file.filename.rsplit('.', 1)[1] visibility = int(request.form['visibility']) album = int(request.form['album']) ip_address = request.remote_addr user = None image = database.Image(extension, original_filename, None, visibility, album, mimetype, ip_address, user) database.db.session.add(image) database.db.session.commit() filename = secure_filename(base62.encode(image.id)) try: file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename + '.' + extension)) except Exception, e: database.db.session.delete(image) database.db.session.commit() print e abort(500) return filename
def image_single(image): image = base62.decode(image.rsplit('.', 1)[0]) image_info = database.Image.query.filter_by(id=image).first() if image_info: base62_filename = base62.encode(image_info.id) filename = base62_filename + '.' + image_info.extension full_filename = app.config['UPLOAD_FOLDER'] + '/' + filename return send_from_directory(app.config['UPLOAD_FOLDER'], filename, attachment_filename=base62_filename, as_inline=True, mimetype=image_info.mimetype) return redirect(url_for('index',))
def upload_picture(): image_names = '' i = 1 if request.method == 'POST': files = request.files.getlist('file[]') for file in files: base_number = database.db.session.query(database.Image).count() + 1 mimetype = file.mimetype if file and allowed_mimetype(mimetype): original_filename = file.filename extension = file.filename.rsplit('.', 1)[1] visibility = int(request.form['visibility']) album = int(request.form['album']) ip_address = request.remote_addr user = None image = database.Image(extension, original_filename, None, visibility, album, mimetype, ip_address, user) database.db.session.add(image) database.db.session.commit() filename = secure_filename(base62.encode(image.id)) try: file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename + '.' + extension)) except Exception, e: database.db.session.delete(image) database.db.session.commit() print e abort(500) image_names += filename if len(files) != i: image_names += '+' i += 1 else: return redirect(url_for('index',)) return redirect(url_for('image_viewer', images=image_names))