F
F
Friend2017-01-04 02:39:19
JavaScript
Friend, 2017-01-04 02:39:19

How to catch file size before uploading to server?

Found this code

<input type="file" id="loadfile" />
<input type="button" value="find size" onclick="findSize()" />
<script type="text/javascript">
    function findSize() {
        var fileInput = $("#loadfile")[0];

        alert(fileInput.files[0].size); // Size returned in bytes.
    }
</script>

but i use django and use in models to load images like this models.ImageField(upload_to='static/photo')
and in html it looks something like this
<form enctype="multipart/form-data" action="albompho" method="post">
                                {% csrf_token %}
                                {{ phal }}
                                <input class="button" type="submit" value="Завантажити">
                            </form>

How can I attach to {{ phal }} id so that I can catch the file size? or advise a more up to date way for Django

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2017-01-04
@Tiran_94

Look at the final code of the page. The field already has an ID. Junga itself adds it by default. For example, if the field is called file, then its id will be id_file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question