Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Files and FileLists path

I am wondering where the file path is stored in a File object in HTML javascript.

I used the Webkit DevTools and got this:

FileList
0: File
    fileName: "script.js"
    fileSize: 71268
    name: "script.js"
    size: 71268
    type: "application/x-javascript"
    __proto__: File
length: 1
__proto__: FileList

The file name, size and types are there(anyone knows why name and size have 2 variables), but the path is not.

Is there any way to find path of the file, and if not, how does the browser and javascript read the file(such as POST methods & determining the type and size)?

like image 549
tcooc Avatar asked Jun 30 '10 20:06

tcooc


1 Answers

As you can read in the WHATWG HTML spec,

[f]or historical reasons, the value IDL attribute prefixes the filename with the string "C:\fakepath\". Some legacy user agents actually included the full path (which was a security vulnerability).

Reading on on MDC, we can see that Mozilla's implementation of the File object has a (non-standard) property named mozFullPath, containing

[t]he full path of the referenced file; available only to code with UniversalFileRead privileges in chrome.

That page also answers your question about the redundant data in the File object: properties fileName and fileSize are deprecated. Also look at W3C's File API Working Draft, where those are not mentioned.

To answer the second part of your question:

if not, how does the browser and JavaScript read the file (such as POST methods & determining the type and size)?

Of course, internally the complete file path can be accessed (and is in several browsers shown to the user), but it's not accessible to JavaScript scripts running in a web page.

By the way, a few years ago there was a discussion about this on the WHATWG mailing list.

like image 114
Marcel Korpel Avatar answered Oct 29 '22 00:10

Marcel Korpel