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);

chashikajw
  • 592
  • 5
  • 18
  • 1
    what does `console.log(acceptedFile[0])` gives you? – D. Seah Jan 19 '21 at 05:56
  • it's actually undefined and let me re-check will let you know – chashikajw Jan 19 '21 at 06:03
  • 1
    what does `console.log(JSON.stringify(acceptedFile))` give you? – D. Seah Jan 19 '21 at 06: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. – chashikajw Jan 19 '21 at 06:51
  • Does this answer your question? [How can I access and process nested objects, arrays or JSON?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json) – Emile Bergeron Jan 19 '21 at 15:39
  • Hi @EmileBergeron what I need was I only saw the object through the console. Btw this is solved already. hanks for pointing out – chashikajw Jan 19 '21 at 15:46
  • It's an auto-comment when flagging as a possible duplicate. You should consider (if you have the option to) accepting the duplicate candidate since it's likely to help others as there are more answers and the answers over there are more complete. Not to mention that your question is likely unreproducible since it was something else (caching) on your side. – Emile Bergeron Jan 19 '21 at 16:59
  • okay great! Thanks for mentioning that! – chashikajw Jan 19 '21 at 17:20

1 Answers1

1

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

Fady Bark
  • 101
  • 2
  • 6
  • 1
    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. – Fady Bark Jan 19 '21 at 05:57
  • 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` – chashikajw Jan 19 '21 at 06:02
  • This is may sound stupid and it probably is considering that we are blind debugging here but does console.log(accpetedFile.File); give anything – Fady Bark Jan 19 '21 at 06:17
  • 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 – chashikajw Jan 19 '21 at 06:51
  • this is working correctly. `acceptedFile[0].name` – chashikajw Jan 19 '21 at 06:53