You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Stefan Droog <sd...@educator.eu> on 2009/05/14 10:53:40 UTC

FileUploadFile FileNotFoundException (Wicket 1.3.5)

Hi all,

Currently I want to upload a file via FileUploadField. However when I select a file and press upload I get a FileNotFoundException (System cannot find the file specified).  File.getCanonicalPath and file.getAbsolutePath both returns the wrong location.

Somebody a clue why?

Regards,
Stefan

Java:

final FileUploadField fileUploadField = new FileUploadField("fileInput2");

                                Form form = new Form("ajax-simpleUpload2"){

                                                private static final long serialVersionUID = -2623469756422643826L;

                                                @Override
                                                protected void onSubmit() {
                                                                final FileUpload upload = fileUploadField.getFileUpload();

                                                                File file = new File(upload.getClientFileName());

                                                                try {
                                                                                file.getCanonicalPath(); //Returns wrong path
                                                                                file.getAbsolutePath(); //Returns wrong path
                                                                                InputStream in = new FileInputStream(file);
                                                                } catch (FileNotFoundException e) {
                                                                                e.printStackTrace();
                                                                } catch (IOException e) {
                                                                                e.printStackTrace();
                                                                }

                                                                super.onSubmit();
                                                }};
                                form.setMultiPart(true);

                                form.add(fileUploadField);
        add(form);


HTML:

                                <form wicket:id="ajax-simpleUpload2">
                                                <fieldset>
                                                                <legend>Upload form</legend>
                                                <p>
                                                <label for="upload">File</label>
                                                <input wicket:id="fileInput2" id="upload" type="file"/>
                                                </p>
                                                <input type="submit" value="Upload!"/>
                                                </fieldset>
                                </form>




________________________________
The information contained in this communication is confidential, intended solely for the use of the individual or entity to whom it is addressed and may be legally privileged and protected by professional secrecy. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. This email does not constitute any commitment from Cordys Holding BV or any of its subsidiaries except when expressly agreed in a written agreement between the intended recipient and Cordys Holding BV or its subsidiaries. Cordys is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt. Cordys does not guarantee that the integrity of this communication has been maintained nor that the communication is free of viruses, interceptions or interference. If you are not the intended recipient of this communication please return the communication to the sender and delete and destroy all copies.

RE: FileUploadFile FileNotFoundException (Wicket 1.3.5)

Posted by Stefan Droog <sd...@educator.eu>.
Martijn,

Thanks for your quick answer. I missed some crucial parts ;)

Folder flr = new Folder("d:\\testUpload");
File file = new File(flr, upload.getClientFileName());
...				
file.createNewFile();                    
upload.writeTo(file);
...

Now it is working properly.

Stefan

-----Original Message-----
From: Martijn Dashorst [mailto:martijn.dashorst@gmail.com] 
Sent: Thursday, May 14, 2009 10:59 AM
To: users@wicket.apache.org
Subject: Re: FileUploadFile FileNotFoundException (Wicket 1.3.5)

Why are you looking up the client filename? Do you have access the the
remote computer your user is on?

Martijn

On Thu, May 14, 2009 at 10:53 AM, Stefan Droog <sd...@educator.eu> wrote:
> Hi all,
>
> Currently I want to upload a file via FileUploadField. However when I select a file and press upload I get a FileNotFoundException (System cannot find the file specified).  File.getCanonicalPath and file.getAbsolutePath both returns the wrong location.
>
> Somebody a clue why?
>
> Regards,
> Stefan
>
> Java:
>
> final FileUploadField fileUploadField = new FileUploadField("fileInput2");
>
>                                Form form = new Form("ajax-simpleUpload2"){
>
>                                                private static final long serialVersionUID = -2623469756422643826L;
>
>                                                @Override
>                                                protected void onSubmit() {
>                                                                final FileUpload upload = fileUploadField.getFileUpload();
>
>                                                                File file = new File(upload.getClientFileName());
>
>                                                                try {
>                                                                                file.getCanonicalPath(); //Returns wrong path
>                                                                                file.getAbsolutePath(); //Returns wrong path
>                                                                                InputStream in = new FileInputStream(file);
>                                                                } catch (FileNotFoundException e) {
>                                                                                e.printStackTrace();
>                                                                } catch (IOException e) {
>                                                                                e.printStackTrace();
>                                                                }
>
>                                                                super.onSubmit();
>                                                }};
>                                form.setMultiPart(true);
>
>                                form.add(fileUploadField);
>        add(form);
>
>
> HTML:
>
>                                <form wicket:id="ajax-simpleUpload2">
>                                                <fieldset>
>                                                                <legend>Upload form</legend>
>                                                <p>
>                                                <label for="upload">File</label>
>                                                <input wicket:id="fileInput2" id="upload" type="file"/>
>                                                </p>
>                                                <input type="submit" value="Upload!"/>
>                                                </fieldset>
>                                </form>
>
>
>
>
> ________________________________
> The information contained in this communication is confidential, intended solely for the use of the individual or entity to whom it is addressed and may be legally privileged and protected by professional secrecy. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. This email does not constitute any commitment from Cordys Holding BV or any of its subsidiaries except when expressly agreed in a written agreement between the intended recipient and Cordys Holding BV or its subsidiaries. Cordys is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt. Cordys does not guarantee that the integrity of this communication has been maintained nor that the communication is free of viruses, interceptions or interference. If you are not the intended recipient of this communication please return the communication to the sender and delete and destroy all copies.
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.5 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: FileUploadFile FileNotFoundException (Wicket 1.3.5)

Posted by Martijn Dashorst <ma...@gmail.com>.
Why are you looking up the client filename? Do you have access the the
remote computer your user is on?

Martijn

On Thu, May 14, 2009 at 10:53 AM, Stefan Droog <sd...@educator.eu> wrote:
> Hi all,
>
> Currently I want to upload a file via FileUploadField. However when I select a file and press upload I get a FileNotFoundException (System cannot find the file specified).  File.getCanonicalPath and file.getAbsolutePath both returns the wrong location.
>
> Somebody a clue why?
>
> Regards,
> Stefan
>
> Java:
>
> final FileUploadField fileUploadField = new FileUploadField("fileInput2");
>
>                                Form form = new Form("ajax-simpleUpload2"){
>
>                                                private static final long serialVersionUID = -2623469756422643826L;
>
>                                                @Override
>                                                protected void onSubmit() {
>                                                                final FileUpload upload = fileUploadField.getFileUpload();
>
>                                                                File file = new File(upload.getClientFileName());
>
>                                                                try {
>                                                                                file.getCanonicalPath(); //Returns wrong path
>                                                                                file.getAbsolutePath(); //Returns wrong path
>                                                                                InputStream in = new FileInputStream(file);
>                                                                } catch (FileNotFoundException e) {
>                                                                                e.printStackTrace();
>                                                                } catch (IOException e) {
>                                                                                e.printStackTrace();
>                                                                }
>
>                                                                super.onSubmit();
>                                                }};
>                                form.setMultiPart(true);
>
>                                form.add(fileUploadField);
>        add(form);
>
>
> HTML:
>
>                                <form wicket:id="ajax-simpleUpload2">
>                                                <fieldset>
>                                                                <legend>Upload form</legend>
>                                                <p>
>                                                <label for="upload">File</label>
>                                                <input wicket:id="fileInput2" id="upload" type="file"/>
>                                                </p>
>                                                <input type="submit" value="Upload!"/>
>                                                </fieldset>
>                                </form>
>
>
>
>
> ________________________________
> The information contained in this communication is confidential, intended solely for the use of the individual or entity to whom it is addressed and may be legally privileged and protected by professional secrecy. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. This email does not constitute any commitment from Cordys Holding BV or any of its subsidiaries except when expressly agreed in a written agreement between the intended recipient and Cordys Holding BV or its subsidiaries. Cordys is neither liable for the proper and complete transmission of the information contained in this communication nor for any delay in its receipt. Cordys does not guarantee that the integrity of this communication has been maintained nor that the communication is free of viruses, interceptions or interference. If you are not the intended recipient of this communication please return the communication to the sender and delete and destroy all copies.
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.5 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org