Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Check for File Exists using Javascript

 
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am coding a JSP file, where there is a need for File Upload. I am using
<input type="file" ...> tag.

Now, suppose end user enters some garbage value in Textfield (in File Upload control), & clicks Submit button it gives javascript error on status bar ('Error on Page' on left hand side bottom region), It says Access is Deniedwhere i am trying to submit this form. If i browse some file using Browse button it works fine.

On click of a Submit button, i am calling a Javascript function which checks for 'Submit' button click & if Submit is clicked, sets action (.action) property to neccessary URL & submits the page to new action url. With alert i have checked for the correctness of the URL & it is fine in both cases.

My question is, Is it possible somehow so that i could say to a user that "file name is incorrect" or similar.

I can't check for file path as this system could be accessed from Windows as well as Linux OS machines.

Thanks in Advance,
Shriniwas
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaScript can not access the local file system so there is nothing you can do to see if a file exists.

Eric
 
Shrinivas Mujumdar
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Eric,

Do you suggest any solution for the above mentioned problem?

Rather, it's not specific to Eric , it's open for everybody.

Thanks in Advance,
Shriniwas
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you could try blurring the file control onfocus:
 
Marshal
Posts: 67515
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Garrett Smith:
you could try blurring the file control onfocus:



How would this help acertain that the file path is correct?
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic