I had a similar problem until I realized that you must specify a file and
not a folder for the upload path (i.e. /tmp/upload/upload.txt not
/tmp/upload). 

HTH,

Shane

-----Original Message-----
From: Brian McSweeney [mailto:[EMAIL PROTECTED]
Sent: Monday, August 18, 2003 7:24 AM
To: 'Struts Users Mailing List'
Subject: RE: file upload problem


Thanks Prashanth,
But I don't think that's the problem.
Thanks anyway though,
Brian

-----Original Message-----
From: Prashanth.S [mailto:[EMAIL PROTECTED] 
Sent: 18 August 2003 11:44
To: Struts Users Mailing List
Subject: Re: file upload problem

hi brian,
try changing the folder permission from read-only??Its just a guess
Thanks
Prashanth


Brian McSweeney <[EMAIL PROTECTED]> wrote:
Hi all,

I'm trying to do a file upload action based on the example
struts-upload.war.

I want to save the uploaded file to a folder on disk. However when I try
to run 
the action I get an error saying I don't have access to the folder. I've
tried 
changing the folder access and also using a different folder. 

I still get a file not found exception which says 

java.io.FileNotFoundException: .. (Access is denied)

I'm using JBoss 3.2.1_tomcat4.1.24. 
Perhaps JBoss restricts folder access?

The code that runs the struts action is:-


AddProductForm frm = (AddProductForm) form;

//retrieve the file representation
FormFile file = frm.getTheFile();

//retrieve the file name
String fileName= file.getFileName();

//retrieve the content type
String contentType = file.getContentType();

//retrieve the file size
String size = (file.getFileSize() + " bytes");

log.info("File details - name: "+fileName);
log.info("File details - contentType: "+contentType);
log.info("File details - size: "+size);


// this is where I get the folder path to save the image into.

String imageStorePath = Init.getImageStorePath();
log.info("the value of imageStorePath is: "+imageStorePath);

try {
//retrieve the file data
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream stream = file.getInputStream();

//write the file to the file specified
OutputStream bos = new FileOutputStream(imageStorePath);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
log.info("The file has been written to \"" + imageStorePath
+ "\"");
//close the stream
stream.close();
}

catch (FileNotFoundException fnfe) {
log.error("Couldn't find the file: "+ fnfe.toString());
}
catch (IOException ioe) {
log.error("io exception: "+ ioe.toString()); 
}
finally{
//destroy the temporary file created
file.destroy();
return mapping.findForward( WebConstants.SUCCESS );
}
}


Any help would be greatly appreciated.
Cheers,
Brian



---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to