Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16954

Re: How to validate a file in a javascript

From Jeff North <jnorthau@yahoo.com.au>
Newsgroups comp.lang.javascript
Subject Re: How to validate a file in a javascript
Date 2012-10-30 17:11 +1100
Organization A noiseless patient Spider
Message-ID <oqnu885m3anro1lv49rppo1l7o60ghbt2k@4ax.com> (permalink)
References (1 earlier) <k6k8kh$svj$1@speranza.aioe.org> <b1e733ca-8409-410a-8f74-bf5c9a6014cc@googlegroups.com> <k6lgcv$vth$2@dont-email.me> <k6m3bf$u39$1@speranza.aioe.org> <k6n33i$938$2@dont-email.me>

Show all headers | View raw


On Mon, 29 Oct 2012 23:22:26 +0000 (UTC), in comp.lang.javascript
Denis McMahon <denismfmcmahon@gmail.com>
<k6n33i$938$2@dont-email.me> wrote:

>| On Mon, 29 Oct 2012 15:20:33 +0100, Cezary Tomczyk wrote:
>| 
>| > W dniu 2012-10-29 09:57, Denis McMahon pisze:
>| >> On Sun, 28 Oct 2012 23:32:33 -0700, Katja wrote:
>| >>
>| >>>> I wouldn't trust on file extensions. As a just a warning for user
>| >>>> then
>| >>>>
>| >>>> it is ok. Just my "5 cents".
>| >>>>
>| >>> I know but I still need it =)
>| >>
>| >> Javascript has no direct access to the filesystem. Thus, it can not
>| >> reliably determine the size of a file. At best, you can do (sub)string
>| >> comparisons and regex checks against a file name entered into a form
>| >> field.
>| > 
>| > Not really. There is some possibilities. See:
>| > https://developer.mozilla.org/en-US/docs/
>| Using_files_from_web_applications
>| > 
>| > There is "but". File API must be implemented in browser.
>| 
>| I think it would be presumptuous for any javascript programmer to assume 
>| that he was going to have any access to the client filesystem unless he 
>| controlled the client. But I'll just knock up a page that will look in 
>| all your files when you visit my server ....
>| 
>| Even if the file api is implemented in the browser, any intelligent 
>| browser is going to provide a means to control its exposure to the web, 
>| and any sensible and security conscious user is going to lock it down as 
>| tightly as they can.
>| 
>| Rgds
>| 
>| Denis McMahon

Denis,
you are 100% correct with regards to the browser accessing the
visitors files but I think that the OP was looking for a way to
process the visitors selected files via the <input type=file ..>
control.

A couple of years ago I too wanted to validate the filetype the
visitor had selected before sending everything to the server. I
couldn't even access the filename because of security restrictions.

It seems these days this restriction has been relaxed. I checked out
https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications#Example.3A_Showing_file%28s%29_size
This works in FF 16, Opera 12, sort of in works in Chrome 22, hardly
works in Safari 5 and doesn't work in IE 9.

Also check out the WHATWG description of type=file -
http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#file-upload-state-%28type=file%29

So while there are some restrictions that have been lifted there is no
standard implementation of the new rules. So I guess it is back to
validating the file server-side.

Cheers

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to validate a file in a javascript Katja <kate.kokatjuhha@gmail.com> - 2012-10-28 11:56 -0700
  Re: How to validate a file in jquery Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-28 21:11 +0000
  Re: How to validate a file in a javascript Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-28 22:38 +0100
    Re: How to validate a file in a javascript Katja <kate.kokatjuhha@gmail.com> - 2012-10-28 23:32 -0700
      Re: How to validate a file in a javascript Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-29 08:57 +0000
        Re: How to validate a file in a javascript Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-29 15:20 +0100
          Re: How to validate a file in a javascript Denis McMahon <denismfmcmahon@gmail.com> - 2012-10-29 23:22 +0000
            Re: How to validate a file in a javascript Jeff North <jnorthau@yahoo.com.au> - 2012-10-30 17:11 +1100
              Re: How to validate a file in a javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-01 21:51 +0100
        Re: How to validate a file in a javascript Dr J R Stockton <reply1244@merlyn.demon.co.uk.invalid> - 2012-10-30 19:47 +0000

csiph-web