0

I'm trying to get name from current uploaded file, I'm sure I'm pretty close, but can't reach exact name. When I'm using this:

$('.technicalDraw').on('change', '#file-upload', function () {
  console.log($(this.files))
})  

I get this output: enter image description here

but when I'm trying something like this:

$('.technicalDraw').on('change', '#file-upload', function () {
  console.log($(this.files.name))
})

I recive this:

enter image description here

How can I reach filename.pdf?

Cheers

3
  • 1
    try with this.files[0].name Commented Jan 19, 2021 at 8:04
  • @CarstenLøvboAndersen doesn't work - shows me this: jQuery.fn.init [prevObject: jQuery.fn.init(1)], and it's without any connection with my uploaded file Commented Jan 19, 2021 at 8:08
  • 1
    Just this.files[0] not $(this.files[0]) - if you're getting jquery.fn.init then you've used $() somewhere Commented Jan 19, 2021 at 8:49

1 Answer 1

2

You can do it like this if there is only 1 file:

$(this)[0].files[0].name

or

this.files[0].name

If there is multiple files I would look thought each file to display the name.

Demo

$(document).on('change', '#file-upload', function () {
  console.log(this.files[0].name)
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="file-upload" type="file" />

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.