Revision history [back]

click to hide/show revision 1
initial version

asked 2013-07-04 13:35:03 +0800

abhisekpanda86 gravatar image abhisekpanda86 flag of India

How to get the absolute path while Attaching a file

I am trying to attach a file from local system. It is working fine but wrong path is showing, when never I am trying to get the attached file's path.

zul file code :

<button id="b_upload" mold="trendy" upload="true" label="Browse" onUpload="@command('onFileUpload')"/>

ViewModel class code :

@Command("onFileUpload")
public void onFileUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) throws IOException {

    UploadEvent upEvent = null;
    ...

    upEvent = (UploadEvent) objUploadEvent;
    if (upEvent != null) {

        Media mediaObj = upEvent.getMedia();
        File fileObj = new File(mediaObj.getName());

        String canonicalPath = fileObj.getCanonicalPath();
        String absolutePath = fileObj.getAbsolutePath();

        System.out.println("CanonicalPath----->>"+canonicalPath);
        System.out.println("AbsolutePath------>>"+absolutePath);

        ...
    }
    ...
}

Example:-

Let, File is present in

C:\Users\Public\Pictures\Sample Pictures

then the out put of the above code is returning,

CanonicalPath----->>E:\Eclipse - Galileo\Penguins.jpg

AbsolutePath------>>E:\Eclipse - Galileo\Penguins.jpg

I want to save the attached file's path in the data base. but in this case I am unable to get the exact attached file path.

Is there any method to get the exact file path.

Thanks in Advance, Abhisek

How to get the absolute path while Attaching a of attached file

I am trying to attach a file from local system. It is working fine but wrong path is showing, when never I am trying to get the attached file's path.

zul file code :

<button id="b_upload" mold="trendy" upload="true" label="Browse" onUpload="@command('onFileUpload')"/>

ViewModel class code :

@Command("onFileUpload")
public void onFileUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) throws IOException {

    UploadEvent upEvent = null;
    ...

    upEvent = (UploadEvent) objUploadEvent;
    if (upEvent != null) {

        Media mediaObj = upEvent.getMedia();
        File fileObj = new File(mediaObj.getName());

        String canonicalPath = fileObj.getCanonicalPath();
        String absolutePath = fileObj.getAbsolutePath();

        System.out.println("CanonicalPath----->>"+canonicalPath);
        System.out.println("AbsolutePath------>>"+absolutePath);

        ...
    }
    ...
}

Example:-

Let, File is present in

C:\Users\Public\Pictures\Sample Pictures

then the out put of the above code is returning,

CanonicalPath----->>E:\Eclipse - Galileo\Penguins.jpg

AbsolutePath------>>E:\Eclipse - Galileo\Penguins.jpg

I want to save the attached file's path in the data base. but in this case I am unable to get the exact attached file path.

Is there any method to get the exact file path.

Thanks in Advance, Abhisek

How to get the absolute path of attached file

I am trying to attach a file from local system. It is working fine but wrong path is showing, when never I am trying to get the attached file's path.

zul file code :

<button id="b_upload" mold="trendy" upload="true" label="Browse" onUpload="@command('onFileUpload')"/>

ViewModel class code :

@Command("onFileUpload")
public void onFileUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) throws IOException {

    UploadEvent upEvent = null;
    ...

    upEvent = (UploadEvent) objUploadEvent;
    if (upEvent != null) {

        Media mediaObj = upEvent.getMedia();
        File fileObj = new File(mediaObj.getName());

        String canonicalPath = fileObj.getCanonicalPath();
        String absolutePath = fileObj.getAbsolutePath();

        System.out.println("CanonicalPath----->>"+canonicalPath);
        System.out.println("AbsolutePath------>>"+absolutePath);

        ...
    }
    ...
}

Example:-

Let, File is present in

C:\Users\Public\Pictures\Sample Pictures

then the out put of the above code is returning,

CanonicalPath----->>E:\Eclipse - Galileo\Penguins.jpg

AbsolutePath------>>E:\Eclipse - Galileo\Penguins.jpg

I want to save the attached file's path in the data base. but in this case I am unable to get the exact attached file path.

Is there any method to get the exact file path.

Thanks in Advance, Abhisek

How to get the absolute path of attached file

I am trying to attach a file from local system. It is working fine but wrong path is showing, when never I am trying to get the attached file's path.

zul file code :

<button id="b_upload" mold="trendy" upload="true" label="Browse" onUpload="@command('onFileUpload')"/>

ViewModel class code :

@Command("onFileUpload")
public void onFileUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) throws IOException {

    UploadEvent upEvent = null;
    ...

    upEvent = (UploadEvent) objUploadEvent;
    if (upEvent != null) {

        Media mediaObj = upEvent.getMedia();
        File fileObj = new File(mediaObj.getName());

        String canonicalPath = fileObj.getCanonicalPath();
        String absolutePath = fileObj.getAbsolutePath();

        System.out.println("CanonicalPath----->>"+canonicalPath);
        System.out.println("AbsolutePath------>>"+absolutePath);

        ...
    }
    ...
}

Example:-

Let, File is present in

C:\Users\Public\Pictures\Sample Pictures

then the out put of the above code is returning,

CanonicalPath----->>E:\Eclipse - Galileo\Penguins.jpg

AbsolutePath------>>E:\Eclipse - Galileo\Penguins.jpg

I want to save the attached file's path in the data base. but in this case I am unable to get the exact attached file path.

Is there any method to get the exact file path.

Thanks in Advance, Abhisek

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More