PDA

View Full Version : Chrome shows always "c:\fakepath\..." in upload field instead of the right path



pegaso52it
3 Jul 2013, 1:20 AM
Hi I'm using Chrome Version 27.0.1453.116 m.

I've a problem in my custom application using File Upload Field
that happens also in online samples application.

Use
http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/form/file-upload.html

Use the first example "Basic File Field", then click "Browse..." button and select the file you want.
The problem is that in upload field the file name is right but the file path shows always: c:\fakepath\...
Also using the "Get File Path" button under the upload field is shown the wrong path.

Then the upload does not works correctly (due to wrong path, I imagine)

With Firefox using the same example are there no problem,

Please, could someone help me to solve this problem?

existdissolve
3 Jul 2013, 4:05 AM
Hi I'm using Chrome Version 27.0.1453.116 m.

I've a problem in my custom application using File Upload Field
that happens also in online samples application.

Use
http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/form/file-upload.html

Use the first example "Basic File Field", then click "Browse..." button and select the file you want.
The problem is that in upload field the file name is right but the file path shows always: c:\fakepath\...
Also using the "Get File Path" button under the upload field is shown the wrong path.

Then the upload does not works correctly (due to wrong path, I imagine)

With Firefox using the same example are there no problem,

Please, could someone help me to solve this problem?

Check out the first couple of paragraphs in the documentation for Ext.form.field.File: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.File

The result of getValue() is entirely browser-dependent.

However, this should have nothing to do with the upload succeeding or failing, as it is the content of the form field, not the path, which is ultimately put in the post to the server.

I have several applications that do file uploads with Ext.form.field.File, so there may be an issue with your implementation if it is succeeding in one browser but failing in another. Can you share some of the code that is failing?

pegaso52it
4 Jul 2013, 1:40 AM
Hi, thank for your answer, first of all.
Excuse me if I have not reply quickly, but I was very busy with other activities.

That's my code that works using Firefox:



MY.Ext.form.MYFileUploadField = Ext.extend(Ext.ux.form.FileUploadField,
{
bindListeners : function()
{
MY.Ext.form.MYFileUploadField.superclass.bindListeners.call(this);
this.fileInput.on(
{
scope : this,
change : function()
{
var v = this.fileInput.dom.value;
this.setValue(v);
this.iFileInputHidden.dom.value = v;
this.fireEvent('fileselected', this, v);
}
});
},

createFileInput : function()
{
MY.Ext.form.MYFileUploadField.superclass.createFileInput.call(this);
this.iFileInputHidden = this.wrap.createChild(
{
id : this.hiddenId,
name : this.hiddenId,
tag : 'input',
type : 'hidden',
value : ''
});
}
});

existdissolve
4 Jul 2013, 2:07 AM
Hi, thank for your answer, first of all.
Excuse me if I have not reply quickly, but I was very busy with other activities.

That's my code that works using Firefox:



MY.Ext.form.MYFileUploadField = Ext.extend(Ext.ux.form.FileUploadField,
{
bindListeners : function()
{
MY.Ext.form.MYFileUploadField.superclass.bindListeners.call(this);
this.fileInput.on(
{
scope : this,
change : function()
{
var v = this.fileInput.dom.value;
this.setValue(v);
this.iFileInputHidden.dom.value = v;
this.fireEvent('fileselected', this, v);
}
});
},

createFileInput : function()
{
MY.Ext.form.MYFileUploadField.superclass.createFileInput.call(this);
this.iFileInputHidden = this.wrap.createChild(
{
id : this.hiddenId,
name : this.hiddenId,
tag : 'input',
type : 'hidden',
value : ''
});
}
});


If you're depending on the bit bolded above (e.g., the setValue()), it's not going to work consistently. Again, if you read the docs (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.File) you'll see that setValue() and getValue() are not implemented the same for the File field as for other ExtJS form fields, because of the cross-browser implementation differences.

dtex-lab
5 Jul 2013, 4:31 AM
As pegaso52it wrote

in the official example at
http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/form/file-upload.html

the problem exists

so nothing to do with extension done.

from official example, please fill the Basic File Field using the browse button you can see that the fully qualified path name is starting with C:\fakepath and not the one really selected.

and also in the example description it says
"The file path reported by the getValue method will"

I read in docs that the setValue is "browser dependent",

The goal is to know from which location of the client the file is uploaded

Anyway i confirm that upload is working anycase
Probably if you are using that informtion for you logging... it is wrong and I agree it is a problem in some cases

existdissolve
5 Jul 2013, 4:53 AM
As pegaso52it wrote

in the official example at
http://docs.sencha.com/extjs/4.2.1/extjs-build/examples/form/file-upload.html

the problem exists

so nothing to do with extension done.

from official example, please fill the Basic File Field using the browse button you can see that the fully qualified path name is starting with C:\fakepath and not the one really selected.

and also in the example description it says
"The file path reported by the getValue method will"

I read in docs that the setValue is "browser dependent",

The goal is to know from which location of the client the file is uploaded

Anyway i confirm that upload is working anycase
Probably if you are using that informtion for you logging... it is wrong and I agree it is a problem in some cases

I understand the "problem" as stated, but it's not really a problem, at least not from an Ext JS perspective. JavaScript does not, and should not, have access to the client's file system, so I'm not sure why anyone would think they should be able to get the full path to a file from a client's machine.

Moreover, I can't understand why one would need that anyway. You certainly don't need it to upload a file, so the only reason would be a nefarious one (or a misguided one that doesn't understand how file uploads work).

I would personally HATE to know that someone was tracking or logging the path to a file on my computer, and would never use the site if I knew they were able to do that. They can have no possible reason to need to know that, unless of course I am installing a program (not JavaScript, of course) in which I grant access to that kind of information.

pegaso52it
16 Jul 2013, 5:16 AM
Thanks for your help, I have solved the problem.

mrinal3199
13 Feb 2014, 5:17 AM
Hi,

How you slved it?? Can yu share it with me. I am also getting same error as C:\fakepath\*...xls in chrome.

Thanks in advance.

existdissolve
13 Feb 2014, 6:34 AM
Hi,

How you slved it?? Can yu share it with me. I am also getting same error as C:\fakepath\*...xls in chrome.

Thanks in advance.

There's nothing to "solve". Review the answer to this thread--it gives the information you need. Also, be aware that this has nothing to do with Ext JS, but is rather more a question of how browser's work and the access which JavaScript has to the client machine.

mrinal3199
13 Feb 2014, 11:05 PM
Hi,
It's a combination of html and java script file which it is calling. You mean to say there is no way to get the correct filepath in chrome in this way? I could understand the security which chrome provides in looking for local drives. But is there any alternate way to get the required filepath not just the filename as we are getting in IE after setting changes?

Thanks again

existdissolve
14 Feb 2014, 2:57 PM
Hi,
It's a combination of html and java script file which it is calling. You mean to say there is no way to get the correct filepath in chrome in this way? I could understand the security which chrome provides in looking for local drives. But is there any alternate way to get the required filepath not just the filename as we are getting in IE after setting changes?

Thanks again

I have no idea. There *might* be some hacks out there that you can implement on a per-instance basis to grant JavaScript access to see this (although I certainly hope there isn't).

But that's beside the point. What possible reason do you have for needing to do this? You certainly don't *need* that path to upload the file. So why do you want it?

mrinal3199
16 Feb 2014, 10:12 PM
Hi,

Thanks for replying. I just not need to upload the file. Actually i am working in alfresco environment and i need to call a java webscript after getting all the UI field details. And in java for reading the xls file i need it's whole directory path so that i can do next process on it. What about hacks?? Did you mean some proxy??