how read content from file in form input type=file

Discussion in 'Javascript' started by Rafal\(sxat\), May 25, 2009.

  1. Hello

    how read content of file selected in form <input type=file...

    Rf
    Rafal\(sxat\), May 25, 2009
    #1
    1. Advertising

  2. Rafal\(sxat\)

    David Mark Guest

    On May 25, 6:02 pm, Conrad Lender <> wrote:
    > On 26/05/09 00:05, Rafal(sxat) wrote:
    >
    > > how read content of file selected in form <input type=file...

    >
    > For security reasons, it's not possible to do that with JavaScript on
    > the client.


    In some browser configurations.

    [snip]
    David Mark, May 25, 2009
    #2
    1. Advertising

  3. Conrad Lender wrote:
    > On 26/05/09 00:05, Rafal(sxat) wrote:
    >> how read content of file selected in form <input type=file...

    >
    > For security reasons,



    it's not possible to do that with JavaScript on
    > the client. You can read the file contents on the server after the form
    > has been submitted.


    It's not possible, but not for security reasons. Arun took over
    FIleUpload spec but doesn't seem to be working on it.

    Gecko has FileList interface, but the problem is that it is not async.
    An async read would be more ideal (because it avoids problems with
    blocking).

    Garrett
    Garrett Smith, May 26, 2009
    #3
  4. Rafal\(sxat\)

    David Mark Guest

    On May 25, 7:21 pm, Garrett Smith <> wrote:
    > Conrad Lender wrote:
    > > On 26/05/09 00:05, Rafal(sxat) wrote:
    > >> how read content of file selected in form <input type=file...

    >
    > > For security reasons,

    >
    > it's not possible to do that with JavaScript on
    >
    > > the client. You can read the file contents on the server after the form
    > > has been submitted.

    >
    > It's not possible, but not for security reasons. Arun took over
    > FIleUpload spec but doesn't seem to be working on it.
    >
    > Gecko has FileList interface, but the problem is that it is not async.
    > An async read would be more ideal (because it avoids problems with
    > blocking).


    You can read local files with Ajax, providing your security settings
    are configured to allow it. The operation is typically synchronous
    because it is a local file. Blocking should not be an issue.
    David Mark, May 26, 2009
    #4
  5. Conrad Lender wrote:
    > On 26/05/09 01:51, Conrad Lender wrote:
    >> On 26/05/09 01:21, Garrett Smith wrote:
    >>> It's not possible, but not for security reasons. Arun took over
    >>> FIleUpload spec but doesn't seem to be working on it.
    >>>
    >>> Gecko has FileList interface, but the problem is that it is not async.
    >>> An async read would be more ideal (because it avoids problems with
    >>> blocking).

    >> I don't know who Arun is, and I couldn't find any information about this
    >> FileList interface. Can you expand?

    >
    > Replying to myself (again):
    > Arun = Mozilla's Arun Ranganathan
    > FileList draft:
    > <http://dev.w3.org/2006/webapi/FileUpload/publish/FileUpload.xhtml>
    >


    Good detective work!

    The problem with blocking is that there may be an issue with reading the
    file. The server tipped over, or maybe the file gets locked up by
    windows (I've never had *that* happen ;).

    A synchronous FileList seems like a great interface until the problems
    (which should be obvious) are recognized. An async approach is avoids
    blocking problems that may occur with remote XHR.

    The other neat thing in there is the file download, or "Save As" proposal.

    Garrett
    Garrett Smith, May 26, 2009
    #5
  6. Rafal\(sxat\)

    David Mark Guest

    On May 25, 11:31 pm, Garrett Smith <> wrote:
    > Conrad Lender wrote:
    > > On 26/05/09 01:51, Conrad Lender wrote:
    > >> On 26/05/09 01:21, Garrett Smith wrote:
    > >>> It's not possible, but not for security reasons. Arun took over
    > >>> FIleUpload spec but doesn't seem to be working on it.

    >
    > >>> Gecko has FileList interface, but the problem is that it is not async..
    > >>> An async read would be more ideal (because it avoids problems with
    > >>> blocking).
    > >> I don't know who Arun is, and I couldn't find any information about this
    > >> FileList interface. Can you expand?

    >
    > > Replying to myself (again):
    > >   Arun = Mozilla's Arun Ranganathan
    > >   FileList draft:
    > >   <http://dev.w3.org/2006/webapi/FileUpload/publish/FileUpload.xhtml>

    >
    > Good detective work!
    >
    > The problem with blocking is that there may be an issue with reading the
    > file. The server tipped over, or maybe the file gets locked up by
    > windows (I've never had *that* happen ;).


    You've probably got bigger problems at that point. IIRC, IE converts
    async XHR requests to synchronous for local (or cached) files. I've
    always found it to be instantaneous, but a down file server could
    certainly block the browser for a bit.

    [snip]
    David Mark, May 26, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hazz
    Replies:
    6
    Views:
    49,412
    SkyUCHC
    Jun 9, 2010
  2. Stanimir Stamenkov
    Replies:
    2
    Views:
    734
    Stanimir Stamenkov
    Oct 25, 2005
  3. Guan
    Replies:
    5
    Views:
    811
  4. fochie
    Replies:
    0
    Views:
    303
    fochie
    Feb 1, 2005
  5. Randell D.
    Replies:
    12
    Views:
    244
    Randell D.
    Jul 6, 2005
Loading...

Share This Page