I am new in flask and making a small application. I uploaded some images to image/upload folder. I can able to see all the images from client side but I also want to get the uploaded image size . How can I do that ?
here is my routes.py
import os
import hashlib
import time
from PIL import Image
from file_counter_app import app, photos
from file_counter_app.form import UploadForm
from flask import render_template, request,url_for,redirect,flash
@app.route('/')
@app.route('/home')
def home():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact')
def contact():
return render_template('contact.html')
@app.route('/upload_picture', methods=['GET', 'POST'])
def upload_picture():
form = UploadForm()
if form.validate_on_submit():
for filename in request.files.getlist('photo'):
str_name = 'admin'+str(int(time.time()))
name = hashlib.md5(str_name.encode('utf-8')).hexdigest()[:15]
photos.save(filename, name=name + '.')
success = True
return redirect(url_for('upload_picture'))
return render_template('upload.html',form=form,)
@app.route('/details')
def show_details():
files_list = os.listdir(app.config['UPLOADED_PHOTOS_DEST'])
return render_template('details.html', files_list=(files_list))
details.html
{% extends 'layout.html' %}
{% block content %}
<h1>File Manager</h1>
<hr>
{% for photo in files_list %}
{{ photo }}
{% endfor %}
{% endblock %}
form.py
from file_counter_app import photos
from flask_wtf import FlaskForm
from flask_wtf.file import FileField,FileRequired,FileAllowed
from wtforms import SubmitField
#class form for image upload
class UploadForm(FlaskForm):
photo = FileField(validators=[FileAllowed(photos,'Image Only!'),FileRequired('Choose a file')])
submit = SubmitField('Upload')