Re: Struts 2 File upload to store the filedata

2011-01-27 Thread PrateekA

Even i was trying implementing the same think but i couldnt make it. I used 

result name=success type=stream
image/jpeg
inputStream
filename=${filename}
1024
/result

But got an exception saying Can not find a java.io.InputStream with the
name [inputStream] in the invocation stack. 

1) couldn't make out what was going wrong. 
2)and if i wish to display in my desired .jsp page with single/multiple
images in it how do i achieve it?

3)and can i use result type as a tiles 2.0?
-- 
View this message in context: 
http://old.nabble.com/Struts-2-File-upload-to-store-the-filedata-tp14168069p30776306.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Struts 2 File upload to store the filedata

2009-06-10 Thread fireapple



Jeromy Evans - Blue Sky Minds wrote:
 
 
 Hi Johnson, I think just need to read up a little more on Struts 2 as it 
 seems you're trying to do too much yourself based on Struts1 experiences 
 rather than let the framework do more of the routine work. Ian Roughly's 
 book is a good place to start: 
 http://www.infoq.com/minibooks/starting-struts2
 
 Anyway, in a previous email you mentioned you know how to open an input 
 stream from the image data in your database:
 
 InputStream in = rs.getBinaryStream(filedata);   
 
 
 The StreamResult requires that an input stream is open and available in 
 a public property in your action.  Here's a section from your new action:
 
 public class MyAction extends ActionSupport {
 //
 private InputStream imageStream;
 
 public String execute() {
// read data from the database ...
//...
   imageStream = rs.getBinaryStream(filedata);
// ...
return SUCCESS;
 }
 
 /** Return an InputStream for the StreamResult */
 public InputStream getImageStream() {
return imageStream;
 }
 
 That's it. We have an open InputStream in a public property in your 
 action.  You don't do anything other than prepare it for reading.
 
 Now your struts.xml requires the action and result definition.  The 
 definition below states that when your action returns success, the 
 stream result type (StreamResult) should be used and that the name of 
 the InputStream property is imageStream (ie. getImageStream()).  That 
 ties it back into the code above.
 
 action name = myaction class=MyAction
result name=success type = stream
 image/jpeg
 imageStream
 filename=image.jpg
 1024
   /result
 /action
 
 Hope that helps.  After you have that working, you can also experiment 
 with getting the content type and filename from properties in your action.
 Hint:  ${contentType}
 
 Regards,
  Jeromy Evans
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 
 
 

Hi, Jeromy, I used the above method to upload and display the images and
succeed. However, if I want to show many images on one page, such as a table
like this:

user_id_1  user_name_1 user_portrait_1(image)
user_id_2  user_name_2 user_portrait_2(image)
user_id_3  user_name_3 user_portrait_3(image)
user_id_4  user_name_4 user_portrait_4(image)
user_id_5  user_name_5 user_portrait_5(image) 

Is there a way to do it?
I used to use display tag to solve similar table display, but with image
URL, it doesn't work.
-- 
View this message in context: 
http://www.nabble.com/Struts-2-File-upload-to-store-the-filedata-tp14168069p23970105.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Not able to locate the file stored using Struts 2 file upload interceptor

2009-05-11 Thread HariniKaushik

Hi all,

I'm trying to upload the file using file upload interceptor.
I have defined the setters and getters for
upload,uploadcontenttype,uploadfilename.
Once tats done the success page displays the path,contenttype and file name.
File path :
D:\Harini\apache-tomcat-6.0.18\work\Catalina\localhost\StartupPoint\upload_170b0f84_1212fa7dbf3__7ffe_.tmp
 
The jsp displays the file uploaded successfuly message , content type and
file name.

But when i check inside the localhost\StartupPoint I'm unable to find that
file(or that file is not present).

Can some one help me on how to locate the file?(or change the location)
1.Is there any other method through which we can retrieve the lost file.
2.I tried to change the directory where file gets stored
(struts.multipart.saveDir= D://Filestore) But still am not able to locate
the file.
Appreciate any help

Thanks,
Harini

-- 
View this message in context: 
http://www.nabble.com/Not-able-to-locate-the-file-stored-using-Struts-2-file-upload-interceptor-tp23482689p23482689.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Not able to locate the file stored using Struts 2 file upload interceptor

2009-05-11 Thread Nils-Helge Garli Hegvik
The FileUploadInterceptor doesn't really store the file for you. It
just makes it available to your action so you can process it. After
the request has finished, the file is deleted. It should all be
described here: http://struts.apache.org/2.1.6/docs/file-upload.html

Nils-H

On Mon, May 11, 2009 at 2:58 PM, HariniKaushik kharin...@yahoo.com wrote:

 Hi all,

 I'm trying to upload the file using file upload interceptor.
 I have defined the setters and getters for
 upload,uploadcontenttype,uploadfilename.
 Once tats done the success page displays the path,contenttype and file name.
 File path :
 D:\Harini\apache-tomcat-6.0.18\work\Catalina\localhost\StartupPoint\upload_170b0f84_1212fa7dbf3__7ffe_.tmp
 The jsp displays the file uploaded successfuly message , content type and
 file name.

 But when i check inside the localhost\StartupPoint I'm unable to find that
 file(or that file is not present).

 Can some one help me on how to locate the file?(or change the location)
 1.Is there any other method through which we can retrieve the lost file.
 2.I tried to change the directory where file gets stored
 (struts.multipart.saveDir= D://Filestore) But still am not able to locate
 the file.
 Appreciate any help

 Thanks,
 Harini

 --
 View this message in context: 
 http://www.nabble.com/Not-able-to-locate-the-file-stored-using-Struts-2-file-upload-interceptor-tp23482689p23482689.html
 Sent from the Struts - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org



-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Struts 2 file upload

2009-02-10 Thread Lund



newton.dave wrote:
 
 Lund wrote:
 I'm using Strurs 2.1.2 and the s:file name=upload label=File / tag
 in
 the jsp page. 
 My problem is that while the fileUpload appears to work most of the time
 I
 do get java.io.FileNotFoundException: on the .tmp file that Struts uses
 as
 part of the process (prob 1 in 10 times). Once this happens of course the
 whole process breaks down.
 
 I boiled the whole process down to a simple test action and tested it
 repeatedly and also checked if anyone else had this issue. It appears
 that
 this issue was fixed as of 2.0.9 release but I am still seeing it.
 
 I'm using commons-fileupload-1.2.1 and commons-io.1.3.2 
 
 Any ideas before I abandon struts 2 fileupload?
 
 Does the same thing happened with an actual release version of S2.1?
 
 Dave
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 
 
 



I've switched to release 2.1.6 and changed the multipartrequest processor to
the Jason Pell version which has improved things. I'll re-post if I get the
same issue again. What I noticed using the Jakarta processor was that the
filename of the  *.tmp used would be out of range. I.e jakarta was looking
for 5.tmp whereas the file available was 7.tmp


-- 
View this message in context: 
http://www.nabble.com/Struts-2-file-upload-tp21915019p21929961.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Struts 2 file upload

2009-02-10 Thread Lund



Lund wrote:
 
 
 
 newton.dave wrote:
 
 Lund wrote:
 I'm using Strurs 2.1.2 and the s:file name=upload label=File / tag
 in
 the jsp page. 
 My problem is that while the fileUpload appears to work most of the time
 I
 do get java.io.FileNotFoundException: on the .tmp file that Struts uses
 as
 part of the process (prob 1 in 10 times). Once this happens of course
 the
 whole process breaks down.
 
 I boiled the whole process down to a simple test action and tested it
 repeatedly and also checked if anyone else had this issue. It appears
 that
 this issue was fixed as of 2.0.9 release but I am still seeing it.
 
 I'm using commons-fileupload-1.2.1 and commons-io.1.3.2 
 
 Any ideas before I abandon struts 2 fileupload?
 
 Does the same thing happened with an actual release version of S2.1?
 
 Dave
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 
 
 
 
 
 
 I've switched to release 2.1.6 and changed the multipartrequest processor
 to the Jason Pell version which has improved things. I'll re-post if I get
 the same issue again. What I noticed using the Jakarta processor was that
 the filename of the  *.tmp used would be out of range. I.e jakarta was
 looking for 5.tmp whereas the file available was 7.tmp
 
 
 



The problem I'm having is that the interceptor-ref name=execAndWait / is
interferring with the file upload. I haven't gone into in any more depth but
if I remove this interceptor then the FileNotFoundException stops

-- 
View this message in context: 
http://www.nabble.com/Struts-2-file-upload-tp21915019p21936355.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



RE: Struts 2 file upload

2009-02-10 Thread Martin Gainty

Brian reported a bug with that interceptor in 2.1.7
https://issues.apache.org/struts/browse/WW-2985
the fix being 
created my own subclass of ExecuteAndWaitInterceptor and overrode
getNewBackgroundProcess to return my own implementation of BackgroundProcess

should test the same error on 2.1.7 distro

Thanks
Martin 
__ 
Disclaimer and confidentiality note 
Everything in this e-mail and any attachments relates to the official business 
of Sender. This transmission is of a confidential nature and Sender does not 
endorse distribution to any party other than intended recipient. Sender does 
not necessarily endorse content contained within this transmission. 




 Date: Tue, 10 Feb 2009 07:43:52 -0800
 From: pie...@hotmail.com
 To: user@struts.apache.org
 Subject: Re: Struts 2 file upload
 
 
 
 
 Lund wrote:
  
  
  
  newton.dave wrote:
  
  Lund wrote:
  I'm using Strurs 2.1.2 and the s:file name=upload label=File / tag
  in
  the jsp page. 
  My problem is that while the fileUpload appears to work most of the time
  I
  do get java.io.FileNotFoundException: on the .tmp file that Struts uses
  as
  part of the process (prob 1 in 10 times). Once this happens of course
  the
  whole process breaks down.
  
  I boiled the whole process down to a simple test action and tested it
  repeatedly and also checked if anyone else had this issue. It appears
  that
  this issue was fixed as of 2.0.9 release but I am still seeing it.
  
  I'm using commons-fileupload-1.2.1 and commons-io.1.3.2 
  
  Any ideas before I abandon struts 2 fileupload?
  
  Does the same thing happened with an actual release version of S2.1?
  
  Dave
  
  
  -
  To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
  For additional commands, e-mail: user-h...@struts.apache.org
  
  
  
  
  
  
  I've switched to release 2.1.6 and changed the multipartrequest processor
  to the Jason Pell version which has improved things. I'll re-post if I get
  the same issue again. What I noticed using the Jakarta processor was that
  the filename of the  *.tmp used would be out of range. I.e jakarta was
  looking for 5.tmp whereas the file available was 7.tmp
  
  
  
 
 
 
 The problem I'm having is that the interceptor-ref name=execAndWait / is
 interferring with the file upload. I haven't gone into in any more depth but
 if I remove this interceptor then the FileNotFoundException stops
 
 -- 
 View this message in context: 
 http://www.nabble.com/Struts-2-file-upload-tp21915019p21936355.html
 Sent from the Struts - User mailing list archive at Nabble.com.
 
 
 -
 To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
 For additional commands, e-mail: user-h...@struts.apache.org
 

_
Windows Liveā„¢: E-mail. Chat. Share. Get more ways to connect. 
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_HM_AE_Faster_022009

Struts 2 file upload

2009-02-09 Thread Lund

Hi 

I'm using Strurs 2.1.2 and the s:file name=upload label=File / tag in
the jsp page. 
My problem is that while the fileUpload appears to work most of the time I
do get java.io.FileNotFoundException: on the .tmp file that Struts uses as
part of the process (prob 1 in 10 times). Once this happens of course the
whole process breaks down.

I boiled the whole process down to a simple test action and tested it
repeatedly and also checked if anyone else had this issue. It appears that
this issue was fixed as of 2.0.9 release but I am still seeing it.

I'm using commons-fileupload-1.2.1 and commons-io.1.3.2 

Any ideas before I abandon struts 2 fileupload?

Thanks
-- 
View this message in context: 
http://www.nabble.com/Struts-2-file-upload-tp21915019p21915019.html
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Struts 2 file upload

2009-02-09 Thread Dave Newton

Lund wrote:

I'm using Strurs 2.1.2 and the s:file name=upload label=File / tag in
the jsp page. 
My problem is that while the fileUpload appears to work most of the time I

do get java.io.FileNotFoundException: on the .tmp file that Struts uses as
part of the process (prob 1 in 10 times). Once this happens of course the
whole process breaks down.

I boiled the whole process down to a simple test action and tested it
repeatedly and also checked if anyone else had this issue. It appears that
this issue was fixed as of 2.0.9 release but I am still seeing it.

I'm using commons-fileupload-1.2.1 and commons-io.1.3.2 


Any ideas before I abandon struts 2 fileupload?


Does the same thing happened with an actual release version of S2.1?

Dave


-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: Struts 2 file upload size validation

2008-05-09 Thread Rubbinio


mgainty wrote:
 
 2.0.11 FileUploadIntereptor.java
 
 ActionContext ac = invocation.getInvocationContext();
 HttpServletRequest request = (HttpServletRequest) 
 ac.get(ServletActionContext.HTTP_REQUEST);
 HashMap map = request.getParameterMap();
 //for further information take a look at
 http://www.docjar.com/docs/api/javax/servlet/ServletRequest.html#getParameterMap
 
 

Tried that and it works as long as the file size validation does not fail in
the interceptor. If it fails the parameter map is empty. Any other ideas.

-- 
View this message in context: 
http://www.nabble.com/Struts-2-file-upload-size-validation-tp17112411p17146914.html
Sent from the Struts - User mailing list archive at Nabble.com.


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



Re: Struts 2 file upload size validation

2008-05-08 Thread Rubbinio

Yes if the file size is OK everything is fine. At first we used the default
stack. Then we took the default and modified it by moving the
fileUploadInterceptor below the params interceptor so it would look
something like this:


interceptor-stack name=ourUploadStack

interceptor-ref name=exception

interceptor-ref name=alias

interceptor-ref name=servletConfig

interceptor-ref name=prepare

interceptor-ref name=i18n

interceptor-ref name=chain

interceptor-ref name=debugging

interceptor-ref name=profiling

interceptor-ref name=scopedModelDriven

interceptor-ref name=modelDriven

interceptor-ref name=checkbox

interceptor-ref name=staticParams

interceptor-ref name=params

  param name=excludeParamsdojo\..*param

interceptor-ref

interceptor-ref name=conversionError

interceptor-ref name=fileUpload

interceptor-ref name=validation

param name=excludeMethodsinput,back,cancel,browseparam

interceptor-ref

interceptor-ref name=workflow

param name=excludeMethodsinput,back,cancel,browseparam

interceptor-ref

interceptor-stack



Thanks
R



Laurie Harper wrote:
 
 Rubbinio wrote:
 Hi,
 
 we are trying to use file upload in Struts 2 and run into the following
 problem.
 
 We have a form with multiple fields among which one is a file input
 field.
 The user must complete the form and then select a file to upload. If the
 file size is larger than what we specify in the struts.properties the
 FileUploadInterceptor validates and adds the error. Up to here everything
 is
 fine however upon having the error passed to the action we want to return
 to
 the same form, display the error and have the rest of fields populated
 with
 the values the user has inputed (except the file field).
 
 The problem is that when we get in the action (validate method) none of
 the
 request parameters (form values) are populated. Everything is empty.
 
 The question is why is this happening and how can we have the form values
 populated in the action so that we can display the page correctly ?
 
 What interceptor stack are you using? Does everything work as expected 
 if the file size does not exceed the size you specify?
 
 L.
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 
 

-- 
View this message in context: 
http://www.nabble.com/Struts-2-file-upload-size-validation-tp17112411p17125070.html
Sent from the Struts - User mailing list archive at Nabble.com.


Struts 2 file upload size validation

2008-05-07 Thread Rubbinio

Hi,

we are trying to use file upload in Struts 2 and run into the following
problem.

We have a form with multiple fields among which one is a file input field.
The user must complete the form and then select a file to upload. If the
file size is larger than what we specify in the struts.properties the
FileUploadInterceptor validates and adds the error. Up to here everything is
fine however upon having the error passed to the action we want to return to
the same form, display the error and have the rest of fields populated with
the values the user has inputed (except the file field).

The problem is that when we get in the action (validate method) none of the
request parameters (form values) are populated. Everything is empty.

The question is why is this happening and how can we have the form values
populated in the action so that we can display the page correctly ?

Thanks
-- 
View this message in context: 
http://www.nabble.com/Struts-2-file-upload-size-validation-tp17112411p17112411.html
Sent from the Struts - User mailing list archive at Nabble.com.


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



Re: Struts 2 file upload size validation

2008-05-07 Thread Martin

Struts 1.2.9
org.apache.struts.chain.servlet.validateActionForm
where the validate method is declared as

protected ActionErrors validate(Context context,
   ActionConfig actionConfig,
   ActionForm actionForm)
//reference the actionForm for access to the form attributes

2.0.11 FileUploadIntereptor.java

ActionContext ac = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) 
ac.get(ServletActionContext.HTTP_REQUEST);

HashMap map = request.getParameterMap();
//for further information take a look at
http://www.docjar.com/docs/api/javax/servlet/ServletRequest.html#getParameterMap

HTH
M
- Original Message - 
From: Rubbinio [EMAIL PROTECTED]

To: user@struts.apache.org
Sent: Wednesday, May 07, 2008 3:24 PM
Subject: Struts 2 file upload size validation




Hi,

we are trying to use file upload in Struts 2 and run into the following
problem.

We have a form with multiple fields among which one is a file input field.
The user must complete the form and then select a file to upload. If the
file size is larger than what we specify in the struts.properties the
FileUploadInterceptor validates and adds the error. Up to here everything 
is
fine however upon having the error passed to the action we want to return 
to
the same form, display the error and have the rest of fields populated 
with

the values the user has inputed (except the file field).

The problem is that when we get in the action (validate method) none of 
the

request parameters (form values) are populated. Everything is empty.

The question is why is this happening and how can we have the form values
populated in the action so that we can display the page correctly ?

Thanks
--
View this message in context: 
http://www.nabble.com/Struts-2-file-upload-size-validation-tp17112411p17112411.html

Sent from the Struts - User mailing list archive at Nabble.com.


-
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]



Re: Struts 2 file upload size validation

2008-05-07 Thread Laurie Harper

Rubbinio wrote:

Hi,

we are trying to use file upload in Struts 2 and run into the following
problem.

We have a form with multiple fields among which one is a file input field.
The user must complete the form and then select a file to upload. If the
file size is larger than what we specify in the struts.properties the
FileUploadInterceptor validates and adds the error. Up to here everything is
fine however upon having the error passed to the action we want to return to
the same form, display the error and have the rest of fields populated with
the values the user has inputed (except the file field).

The problem is that when we get in the action (validate method) none of the
request parameters (form values) are populated. Everything is empty.

The question is why is this happening and how can we have the form values
populated in the action so that we can display the page correctly ?


What interceptor stack are you using? Does everything work as expected 
if the file size does not exceed the size you specify?


L.


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



Re: Struts 2 file upload size validation

2008-05-07 Thread Laurie Harper

The OP wrote:
 we are trying to use file upload in Struts 2...

Martin wrote:

Struts 1.2.9


Doh!


org.apache.struts.chain.servlet.validateActionForm
where the validate method is declared as

protected ActionErrors validate(Context context,
   ActionConfig actionConfig,
   ActionForm actionForm)
//reference the actionForm for access to the form attributes

2.0.11 FileUploadIntereptor.java

ActionContext ac = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) 
ac.get(ServletActionContext.HTTP_REQUEST);

HashMap map = request.getParameterMap();
//for further information take a look at
http://www.docjar.com/docs/api/javax/servlet/ServletRequest.html#getParameterMap 



HTH
M
- Original Message - From: Rubbinio [EMAIL PROTECTED]
To: user@struts.apache.org
Sent: Wednesday, May 07, 2008 3:24 PM
Subject: Struts 2 file upload size validation




Hi,

we are trying to use file upload in Struts 2 and run into the following
problem.

We have a form with multiple fields among which one is a file input 
field.

The user must complete the form and then select a file to upload. If the
file size is larger than what we specify in the struts.properties the
FileUploadInterceptor validates and adds the error. Up to here 
everything is
fine however upon having the error passed to the action we want to 
return to
the same form, display the error and have the rest of fields populated 
with

the values the user has inputed (except the file field).

The problem is that when we get in the action (validate method) none 
of the

request parameters (form values) are populated. Everything is empty.

The question is why is this happening and how can we have the form values
populated in the action so that we can display the page correctly ?

Thanks
--
View this message in context: 
http://www.nabble.com/Struts-2-file-upload-size-validation-tp17112411p17112411.html 


Sent from the Struts - User mailing list archive at Nabble.com.


-
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]



Struts 1 Struts 2 file upload problem

2008-04-22 Thread Rubbinio

Hi,

we have an old application written in Struts 1 and we started adding new
features in Struts 2. In the old application we had a file upload form which
was working fine.

After adding Struts 2, the form does not work anymore because the file field
is not populated in the form anymore and it is always null.

In the sever console we can see : org.apache.struts2.dispatcher.Dispatcher
getSaveDir which does not show up if Struts 2 is removed.

Is there any way to have both file uploads ( Struts 1 and 2 ) working in
parallel ? And if yes how ? If not how can we disable the Struts 2 file
upload ?

Thanks


-- 
View this message in context: 
http://www.nabble.com/Struts-1---Struts-2-file-upload-problem-tp16824755p16824755.html
Sent from the Struts - User mailing list archive at Nabble.com.


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



Re: Struts 1 Struts 2 file upload problem

2008-04-22 Thread Laurie Harper

Rubbinio wrote:

Hi,

we have an old application written in Struts 1 and we started adding new
features in Struts 2. In the old application we had a file upload form which
was working fine.

After adding Struts 2, the form does not work anymore because the file field
is not populated in the form anymore and it is always null.

In the sever console we can see : org.apache.struts2.dispatcher.Dispatcher
getSaveDir which does not show up if Struts 2 is removed.

Is there any way to have both file uploads ( Struts 1 and 2 ) working in
parallel ? And if yes how ? If not how can we disable the Struts 2 file
upload ?


These should be able to co-exist without problem. You need to include 
details of your configuration; I suspect you have your Struts 1 servlet 
mapping and Struts 2 filter mapping configured in such a way as to cause 
both to be invoked on the same request. Since multi-part request parsing 
is handled by Struts, not the container, this could well cause a conflict.


If that's not what you've done, or you fix that and still have the same 
problem, re-post with complete details of your relevant configuration 
(including web.xml, struts.xml and struts-config.xml excerpts at least) 
so we have enough information to help.


L.


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



Re: Struts 1 Struts 2 file upload problem

2008-04-22 Thread Radu Solomon

Thank you.

You were absolutely right. our struts 2 filter was using /* and the 
Struts 1 servlet mapping *.do. Once I changed the struts 2 to *.action 
it all went back to normal.




Laurie Harper wrote:

Rubbinio wrote:

Hi,

we have an old application written in Struts 1 and we started adding new
features in Struts 2. In the old application we had a file upload 
form which

was working fine.

After adding Struts 2, the form does not work anymore because the 
file field

is not populated in the form anymore and it is always null.

In the sever console we can see : 
org.apache.struts2.dispatcher.Dispatcher

getSaveDir which does not show up if Struts 2 is removed.

Is there any way to have both file uploads ( Struts 1 and 2 ) working in
parallel ? And if yes how ? If not how can we disable the Struts 2 file
upload ?


These should be able to co-exist without problem. You need to include 
details of your configuration; I suspect you have your Struts 1 
servlet mapping and Struts 2 filter mapping configured in such a way 
as to cause both to be invoked on the same request. Since multi-part 
request parsing is handled by Struts, not the container, this could 
well cause a conflict.


If that's not what you've done, or you fix that and still have the 
same problem, re-post with complete details of your relevant 
configuration (including web.xml, struts.xml and struts-config.xml 
excerpts at least) so we have enough information to help.


L.


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


Re: Struts 2 File upload to store the filedata

2007-12-07 Thread Martin Gainty
a static inner class example is located at
org.apache.struts2.util.StrutsUtil
called static class ResponseWrapper notice the
sout = new ServletOutputStreamWrapper(strout);
assignment

Difficult to determine what your needs are without more information
M--
- Original Message -
From: Johnson nickel [EMAIL PROTECTED]
To: user@struts.apache.org
Sent: Friday, December 07, 2007 8:39 AM
Subject: Re: Struts 2 File upload to store the filedata




 Hi Evans,

   I digged in google examples in StreamResult. But, i can't
 understand.
  I want to display the images in browser Using StremResult.

   Instead of ServletOutputStream out=
 response.getOutputStream();
 How can i use StreamResult.

 Can u give some examples pgm?? That will be helpful..


 Regards,
 Johnson
 --
 View this message in context:
http://www.nabble.com/Struts-2-File-upload-to-store-the-filedata-tf4948427.h
tml#a14212685
 Sent from the Struts - User mailing list archive at Nabble.com.



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



Re: Struts 2 File upload to store the filedata

2007-12-07 Thread Johnson nickel


Hi Evans,

  I digged in google examples in StreamResult. But, i can't
understand.
 I want to display the images in browser Using StremResult.

  Instead of ServletOutputStream out=
response.getOutputStream();
How can i use StreamResult.

Can u give some examples pgm?? That will be helpful..


Regards,
Johnson
-- 
View this message in context: 
http://www.nabble.com/Struts-2-File-upload-to-store-the-filedata-tf4948427.html#a14212685
Sent from the Struts - User mailing list archive at Nabble.com.


Re: Struts 2 File upload to store the filedata

2007-12-07 Thread Jeromy Evans

Don't use ServletOutputStream within Struts2.  Use a StreamResult instead:

http://struts.apache.org/2.0.11/docs/stream-result.html

In the example provided in the above link, inputName references a 
property in your action that's an InputStream you need to create from 
your data.


InputStream getInputStream();

If you search, you'll find plenty of examples using StreamResult.

regards,
Jeromy Evans

Johnson nickel wrote:
Hi Evans,   
   I want to display the images in browser from the database.
I have added   my code.It throws null pointer Exception. 
In my action, i have implements
ServletRequestAware,ServletResponseAware interface. I want to
know if ServletOutputStream is working in Struts 2.0.6 action class.  
   Can u give a solution for this.   
InputStream in = rs.getBinaryStream(filedata);   
   response.setContentType(image/jpeg);

   response.addHeader(Content-Disposition,inline;filename= filename);
 ServletOutputStream out = response.getOutputStream();
  out.flush();

int c;
 while ((c = in.read()) != -1) 
{

out.write(c);
}
in.close();
out.close();
  



No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.503 / Virus Database: 269.16.15/1174 - Release Date: 6/12/2007 10:11 AM
  



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



Re: Struts 2 File upload to store the filedata

2007-12-07 Thread Johnson nickel

Hi Evans,   
   I want to display the images in browser from the database.
I have added   my code.It throws null pointer Exception. 
In my action, i have implements
ServletRequestAware,ServletResponseAware interface. I want to
know if ServletOutputStream is working in Struts 2.0.6 action class.  
   Can u give a solution for this.   
InputStream in = rs.getBinaryStream(filedata);   
   response.setContentType(image/jpeg);
   response.addHeader(Content-Disposition,inline;filename= filename);
 ServletOutputStream out = response.getOutputStream();
  out.flush();
int c;
 while ((c = in.read()) != -1) 
{
out.write(c);
}
in.close();
out.close();
-- 
View this message in context: 
http://www.nabble.com/Struts-2-File-upload-to-store-the-filedata-tf4948427.html#a14211550
Sent from the Struts - User mailing list archive at Nabble.com.


Re: Struts 2 File upload to store the filedata

2007-12-07 Thread Jeromy Evans

Johnson nickel wrote:

Hi Evans,

  I digged in google examples in StreamResult. But, i can't
understand.
 I want to display the images in browser Using StremResult.

  Instead of ServletOutputStream out=
response.getOutputStream();
How can i use StreamResult.

Can u give some examples pgm?? That will be helpful..



Regards,
Johnson
  
Hi Johnson, I think just need to read up a little more on Struts 2 as it 
seems you're trying to do too much yourself based on Struts1 experiences 
rather than let the framework do more of the routine work. Ian Roughly's 
book is a good place to start: 
http://www.infoq.com/minibooks/starting-struts2


Anyway, in a previous email you mentioned you know how to open an input 
stream from the image data in your database:


InputStream in = rs.getBinaryStream(filedata);   



The StreamResult requires that an input stream is open and available in 
a public property in your action.  Here's a section from your new action:


public class MyAction extends ActionSupport {
//
private InputStream imageStream;

public String execute() {
  // read data from the database ...
  //...
 imageStream = rs.getBinaryStream(filedata);
  // ...
  return SUCCESS;
}

/** Return an InputStream for the StreamResult */
public InputStream getImageStream() {
  return imageStream;
}

That's it. We have an open InputStream in a public property in your 
action.  You don't do anything other than prepare it for reading.


Now your struts.xml requires the action and result definition.  The 
definition below states that when your action returns success, the 
stream result type (StreamResult) should be used and that the name of 
the InputStream property is imageStream (ie. getImageStream()).  That 
ties it back into the code above.


action name = myaction class=MyAction
  result name=success type = stream
   param name=contentTypeimage/jpeg/param
   param name=inputNameimageStream/param
   param name=contentDispositionfilename=image.jpg/param
   param name=bufferSize1024/param
 /result
/action

Hope that helps.  After you have that working, you can also experiment 
with getting the content type and filename from properties in your action.

Hint:  param name=contentType${contentType}/param

Regards,
Jeromy Evans


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



Re: Struts 2 File upload to store the filedata

2007-12-05 Thread Johnson nickel

Hi Jeromy Evans,

  Thanks for your reply. I would like to insert the images  into
my
  Databases. For that, i'm using byte[] array.
  In Struts 1.3, 
 I used FormFile class. From this class i got the method
getFileData();

In my db, ps.setBytes(1,filedata); // to store the binary
datas in DB.

/*FormFile mtfile = form.getTheFile();
  byte[] filedata = mtfile.getFileData();*/
  
  

In Struts 2.0.6,
UploadAction.java
   private File upload;
   private String contentType;
   private String filename;
   byte [] filedata; // to Store the binary datas

  public void setUpload(File upload) {
this.upload = upload;
}
 same as setUploadContentType,getUploadFileName these are the three
methods default for
 the FileUpload Interceptor.
 
 In jsp,
s:file=upload label=file/


Regards,
John
-- 
View this message in context: 
http://www.nabble.com/Struts-2-File-upload-to-store-the-filedata-tf4948427.html#a14168972
Sent from the Struts - User mailing list archive at Nabble.com.


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



Re: Struts 2 File upload to store the filedata

2007-12-05 Thread Jeromy Evans



Johnson nickel wrote:

Hi Jeromy Evans,

  Thanks for your reply. I would like to insert the images  into
my
  Databases. For that, i'm using byte[] array.
  In Struts 1.3, 
 I used FormFile class. From this class i got the method

getFileData();

In my db, ps.setBytes(1,filedata); // to store the binary
datas in DB.

/*FormFile mtfile = form.getTheFile();
  byte[] filedata = mtfile.getFileData();*/
  
  
  

Ahh, ok.

In Struts2, the file is a reference to a temporary file created on your 
server.  If it's not HUGE, just read it into a byte array. 
The code follows.  This code is a fairly standard approach to read an 
arbitrary length inputstream into a byte array one chunk at a time.

If the file can be HUGE, see my comment at bottom.

byte[] filedata = readInputStream(new FileInputStream(upload));

/** Read an input stream in its entirety into a byte array */
   public static byte[] readInputStream(InputStream inputStream) throws 
IOException {

   int bufSize = 1024 * 1024;
   byte[] content;

   Listbyte[] parts = new LinkedList();
   InputStream in = new BufferedInputStream(inputStream);

   byte[] readBuffer = new byte[bufSize];
   byte[] part = null;
   int bytesRead = 0;

   // read everyting into a list of byte arrays
   while ((bytesRead = in.read(readBuffer, 0, bufSize)) != -1) {
   part = new byte[bytesRead];
   System.arraycopy(readBuffer, 0, part, 0, bytesRead);
   parts.add(part);
   }

   // calculate the total size
   int totalSize = 0;
   for (byte[] partBuffer : parts) {
   totalSize += partBuffer.length;
   }

   // allocate the array
   content = new byte[totalSize];
   int offset = 0;
   for (byte[] partBuffer : parts) {
   System.arraycopy(partBuffer, 0, content, offset, 
partBuffer.length);

   offset += partBuffer.length;
   }

   return content;
   }

Disclaimer: This approach is limited to small files (multiple megabytes 
rather than hundreds/gigs) because of the inefficient memory 
consumption.  It's also quite slow as the commons fileuploader first 
receives all the data, then writes the entire temporary file, then it's 
read again entirely  into memory, then written back to your 
database/filesystem.  There's no other built-in approach in Struts2 but 
you'll find ajax fileuploaders on the web that handle massive files 
better than this.


regards,
Jeromy Evans



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



Re: Struts 2 File upload to store the filedata

2007-12-05 Thread Jeromy Evans

Johnson nickel wrote:

Hi everyone,

I am using Struts 2 and using s:file tag to upload a file.
But I get that file as a 'File' object in my action class and using
getFileName() on that File object returns me some arbitrary value (something
like upload__5b41f107_1127b4befe0__8000_.tmp). I want to
retrieve things like Filedata to store the binary datas in my databases.
which was possible in
struts 1.1 using methods like on getFiledata() using byte [] array FormFile
Object.
 
How do I accomplish the same in Struts 2 ? 


Regards,
John
  

Hi John,
If the file property in your action is called anUploadFile, then also 
add the following properties to your action:


String anUploadFileContentType
String anUploadFileFileName

If you require any other kinds of filedata (eg. size) you'll have to 
obtain it from the File object.


ie.
void setAnUploadFile(File file);
void setAnUploadFileFileName(String name)
void setAnUploadFileContentType(String contentType)

For more information, see the FileUploadInterceptor: 
http://struts.apache.org/2.0.11/docs/file-upload-interceptor.html


regards,
Jeromy Evans




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



Struts 2 File upload to store the filedata

2007-12-05 Thread Johnson nickel

Hi everyone,

I am using Struts 2 and using s:file tag to upload a file.
But I get that file as a 'File' object in my action class and using
getFileName() on that File object returns me some arbitrary value (something
like upload__5b41f107_1127b4befe0__8000_.tmp). I want to
retrieve things like Filedata to store the binary datas in my databases.
which was possible in
struts 1.1 using methods like on getFiledata() using byte [] array FormFile
Object.
 
How do I accomplish the same in Struts 2 ? 

Regards,
John
-- 
View this message in context: 
http://www.nabble.com/Struts-2-File-upload-to-store-the-filedata-tf4948427.html#a14168069
Sent from the Struts - User mailing list archive at Nabble.com.


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