2

I have a Js file object like below in the image. What I need to do is read the name of the file. This file comes from dropzone( uploading task). Is anyone can help me.

enter image description here

I tried it in the following ways in the code.

onDrop = (acceptedFile) => {
        
        console.log("check file", acceptedFile);  // this is the object in above image

        
}

Is anyone can help me ? This is a react application.

Edit: this was caused a debugging issue with the cache. SInce I closed the question. this is working as expected. console.log(acceptedFile[0].name);

8
  • 1
    what does console.log(acceptedFile[0]) gives you? Commented Jan 19, 2021 at 5:56
  • it's actually undefined and let me re-check will let you know Commented Jan 19, 2021 at 6:03
  • 1
    what does console.log(JSON.stringify(acceptedFile)) give you? Commented Jan 19, 2021 at 6:04
  • it was worked. Console.log(acceptedFile[0].name); this is working. previously I have debugged with cached and it doesn't get reflected. my bad thank you very much for all. Commented Jan 19, 2021 at 6:51
  • Does this answer your question? How can I access and process nested objects, arrays or JSON? Commented Jan 19, 2021 at 15:39

1 Answer 1

1

Have you tried console.log(accpetedFile[0]['name']);

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

5 Comments

Thanks, didn't read the accpetedFile[0].name in the original post, which is rather weird since I recreated the object and it worked fine, can you please comment tell OP to show us the cropped error messages in a comment, I cannot comment yet.
this gives me exception in console CreateEditForm.jsx:178 Uncaught (in promise) TypeError: Cannot read property '0' of undefined at Xi.onDrop (CreateEditForm.jsx:178) at onDrop (CreateEditForm.jsx:760) at index.js:643
This is may sound stupid and it probably is considering that we are blind debugging here but does console.log(accpetedFile.File); give anything
it was worked. previously I have debugged with cached and it doesn't get reflected. my bad thank you very much for all. I edited the question with that
this is working correctly. acceptedFile[0].name

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.