You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bill Bohnenberger <bi...@gmail.com> on 2009/09/04 20:40:20 UTC
problem uploading a text file
Ok, I'm sure I must be doing something dumb here, but I can't seem to find
it. I'm have a problem uploading a simple text file... when I try to a file
named "test.txt", I get an action error message "File upload error: invalid
data." and all my file variables (see below) are null when the action method
gets called.
Here's my setup:
Config:
<action name="BulkUpload_*" class="com.rp.db.actions.BulkUpload"
method="{1}">
<interceptor-ref name="basicStack"/>
<interceptor-ref name="fileUpload">
<param name="maximumSize">8192000</param>
<param
name="allowedTypes">image/jpeg,image/gif,text/plain</param>
</interceptor-ref>
<interceptor-ref name="validation"/>
<interceptor-ref name="workflow"/>
<result name="input">bulkUpload.jsp</result>
<result name="done" type="redirect">Menu_init</result>
<result name="login" type="redirect">Login_init</result>
</action>
Relevant jsp code:
<s:form action="BulkUpload_doCommand" method="post"
enctype="multipart/form-data">
<s:file label="Bulk File" name="upload" size="45"/>
<s:submit name="command" value="Upload File"/>
<s:submit name="command" value="Cancel"/>
</s:form>
Action excerpts:
...
private String uploadContentType;
private String uploadFileName;
private File upload;
...
public void setUpload(File upload)
{
this.upload = upload;
}
public void setUploadFileName(String uploadFileName)
{
this.uploadFileName = uploadFileName;
}
public void setUploadContentType(String uploadContentType)
{
this.uploadContentType = uploadContentType;
}
As I mentioned above, when I use this form to upload a text file named
"test.txt" I get the action error message "File upload error: invalid data."
and all my "upload..." variables are null.
Thanks,
Bill
Re: problem uploading a text file
Posted by Rusty Wright <ru...@gmail.com>.
I make it a point to try and remember to click that red box to stop tomcat as soon as I'm done playing with it. My preferred steps (when I can remember) are: stop tomcat, edit files, click the build button and/or do a mvn package, click the Publish to server button for tomcat, then click the Start server green arrow. I used to have to right click on the project under tomcat and remove it, then remove tomcat, then re-add them both; it only took a few clicks. But I haven't had to do that since the latest eclipse came out.
Tommy Pham wrote:
> ----- Original Message ----
>> From: Bill Bohnenberger <bi...@gmail.com>
>> To: Struts Users Mailing List <us...@struts.apache.org>
>> Sent: Friday, September 4, 2009 2:50:47 PM
>> Subject: Re: problem uploading a text file
>>
>> Well, I am the one who is confused, for sure. I restarted eclipse and now I
>> can upload *.txt files just fine with my original xml:
>>
>>
>> method="{1}">
>> bulkUpload.jsp
>> Menu_init
>> Login_init
>>
>>
>> Arrg, this is not the first time Eclipse has refused to work properly in
>> "hosted" mode until I restarted it. But this time I totally forgot to try
>> that tactic :( Sorry for the bother!
>>
>> Bill
>>
>
> I've noticed the similar problem with Eclipse 3.5 (Build id: 20090619-0625). It doesn't seem to (automatically) synchronize properly as it did with 3.4.2. My development time gone up because I have to manually redeploy and/or restart the server more often.
>
> Regards,
> Tommy
>
>> On Fri, Sep 4, 2009 at 1:41 PM, Chris Pratt wrote:
>>
>>> I guess I don't understand why the interceptor would care what the content
>>> of the file is. It's only job is to inject the parameters into the action.
>>> (*Chris*)
>>>
>>> On Fri, Sep 4, 2009 at 1:24 PM, Bill Bohnenberger
>>>> wrote:
>>>> Thanks, Chris, but I don't think that's the problem. I have another jsp
>>>> page
>>>> and associated action that uploads .jpg and .gif images ok with the same
>>>> variables...the only difference is that I am tying to get the fileUpload
>>>> interceptor to accept a *.txt file. (Sorry, I should've mentioned all
>>> this
>>>> in my original post)
>>>>
>>>> Bill
>>>>
>>>> On Fri, Sep 4, 2009 at 12:36 PM, Chris Pratt
>>>>> wrote:
>>>>> I believe the documentation is incorrect on the web. The setUpload
>>>> doesn't
>>>>> take a File object, it takes a String that is the fully qualified path
>>> to
>>>>> the temporary file created by the internal upload support of struts.
>>> So
>>>>> what you actually need is:
>>>>>
>>>>> public void setUpload(String upload)
>>>>> {
>>>>> this.upload = new File(upload);
>>>>> }
>>>>>
>>>>> (*Chris*)
>>>>>
>>>>> On Fri, Sep 4, 2009 at 11:40 AM, Bill Bohnenberger <
>>> bill98122@gmail.com
>>>>>> wrote:
>>>>>> Ok, I'm sure I must be doing something dumb here, but I can't seem to
>>>>> find
>>>>>> it. I'm have a problem uploading a simple text file... when I try to
>>> a
>>>>> file
>>>>>> named "test.txt", I get an action error message "File upload error:
>>>>> invalid
>>>>>> data." and all my file variables (see below) are null when the action
>>>>>> method
>>>>>> gets called.
>>>>>>
>>>>>> Here's my setup:
>>>>>>
>>>>>> Config:
>>>>>>
>>>>>>
>>>>>> method="{1}">
>>>>>>
>>>>>>
>>>>>> 8192000
>>>>>>
>>>>>> name="allowedTypes">image/jpeg,image/gif,text/plain
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> bulkUpload.jsp
>>>>>> Menu_init
>>>>>> Login_init
>>>>>>
>>>>>>
>>>>>> Relevant jsp code:
>>>>>>
>>>>>>
>>>>>> enctype="multipart/form-data">
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Action excerpts:
>>>>>> ...
>>>>>> private String uploadContentType;
>>>>>> private String uploadFileName;
>>>>>> private File upload;
>>>>>> ...
>>>>>> public void setUpload(File upload)
>>>>>> {
>>>>>> this.upload = upload;
>>>>>> }
>>>>>> public void setUploadFileName(String uploadFileName)
>>>>>> {
>>>>>> this.uploadFileName = uploadFileName;
>>>>>> }
>>>>>> public void setUploadContentType(String uploadContentType)
>>>>>> {
>>>>>> this.uploadContentType = uploadContentType;
>>>>>> }
>>>>>>
>>>>>> As I mentioned above, when I use this form to upload a text file
>>> named
>>>>>> "test.txt" I get the action error message "File upload error: invalid
>>>>>> data."
>>>>>> and all my "upload..." variables are null.
>>>>>>
>>>>>> Thanks,
>>>>>> Bill
>>>>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: problem uploading a text file
Posted by Tommy Pham <to...@yahoo.com>.
----- Original Message ----
> From: Bill Bohnenberger <bi...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Friday, September 4, 2009 2:50:47 PM
> Subject: Re: problem uploading a text file
>
> Well, I am the one who is confused, for sure. I restarted eclipse and now I
> can upload *.txt files just fine with my original xml:
>
>
> method="{1}">
> bulkUpload.jsp
> Menu_init
> Login_init
>
>
> Arrg, this is not the first time Eclipse has refused to work properly in
> "hosted" mode until I restarted it. But this time I totally forgot to try
> that tactic :( Sorry for the bother!
>
> Bill
>
I've noticed the similar problem with Eclipse 3.5 (Build id: 20090619-0625). It doesn't seem to (automatically) synchronize properly as it did with 3.4.2. My development time gone up because I have to manually redeploy and/or restart the server more often.
Regards,
Tommy
> On Fri, Sep 4, 2009 at 1:41 PM, Chris Pratt wrote:
>
> > I guess I don't understand why the interceptor would care what the content
> > of the file is. It's only job is to inject the parameters into the action.
> > (*Chris*)
> >
> > On Fri, Sep 4, 2009 at 1:24 PM, Bill Bohnenberger
> > >wrote:
> >
> > > Thanks, Chris, but I don't think that's the problem. I have another jsp
> > > page
> > > and associated action that uploads .jpg and .gif images ok with the same
> > > variables...the only difference is that I am tying to get the fileUpload
> > > interceptor to accept a *.txt file. (Sorry, I should've mentioned all
> > this
> > > in my original post)
> > >
> > > Bill
> > >
> > > On Fri, Sep 4, 2009 at 12:36 PM, Chris Pratt
> > > >wrote:
> > >
> > > > I believe the documentation is incorrect on the web. The setUpload
> > > doesn't
> > > > take a File object, it takes a String that is the fully qualified path
> > to
> > > > the temporary file created by the internal upload support of struts.
> > So
> > > > what you actually need is:
> > > >
> > > > public void setUpload(String upload)
> > > > {
> > > > this.upload = new File(upload);
> > > > }
> > > >
> > > > (*Chris*)
> > > >
> > > > On Fri, Sep 4, 2009 at 11:40 AM, Bill Bohnenberger <
> > bill98122@gmail.com
> > > > >wrote:
> > > >
> > > > > Ok, I'm sure I must be doing something dumb here, but I can't seem to
> > > > find
> > > > > it. I'm have a problem uploading a simple text file... when I try to
> > a
> > > > file
> > > > > named "test.txt", I get an action error message "File upload error:
> > > > invalid
> > > > > data." and all my file variables (see below) are null when the action
> > > > > method
> > > > > gets called.
> > > > >
> > > > > Here's my setup:
> > > > >
> > > > > Config:
> > > > >
> > > > >
> > > > > method="{1}">
> > > > >
> > > > >
> > > > > 8192000
> > > > >
> > > > > name="allowedTypes">image/jpeg,image/gif,text/plain
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > bulkUpload.jsp
> > > > > Menu_init
> > > > > Login_init
> > > > >
> > > > >
> > > > > Relevant jsp code:
> > > > >
> > > > >
> > > > > enctype="multipart/form-data">
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > Action excerpts:
> > > > > ...
> > > > > private String uploadContentType;
> > > > > private String uploadFileName;
> > > > > private File upload;
> > > > > ...
> > > > > public void setUpload(File upload)
> > > > > {
> > > > > this.upload = upload;
> > > > > }
> > > > > public void setUploadFileName(String uploadFileName)
> > > > > {
> > > > > this.uploadFileName = uploadFileName;
> > > > > }
> > > > > public void setUploadContentType(String uploadContentType)
> > > > > {
> > > > > this.uploadContentType = uploadContentType;
> > > > > }
> > > > >
> > > > > As I mentioned above, when I use this form to upload a text file
> > named
> > > > > "test.txt" I get the action error message "File upload error: invalid
> > > > > data."
> > > > > and all my "upload..." variables are null.
> > > > >
> > > > > Thanks,
> > > > > Bill
> > > > >
> > > >
> > >
> >
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: problem uploading a text file
Posted by Bill Bohnenberger <bi...@gmail.com>.
Well, I am the one who is confused, for sure. I restarted eclipse and now I
can upload *.txt files just fine with my original xml:
<action name="BulkUpload_*" class="com.rp.db.actions.BulkUpload"
method="{1}">
<result name="input">bulkUpload.jsp</result>
<result name="done" type="redirect">Menu_init</result>
<result name="login" type="redirect">Login_init</result>
</action>
Arrg, this is not the first time Eclipse has refused to work properly in
"hosted" mode until I restarted it. But this time I totally forgot to try
that tactic :( Sorry for the bother!
Bill
On Fri, Sep 4, 2009 at 1:41 PM, Chris Pratt <th...@gmail.com> wrote:
> I guess I don't understand why the interceptor would care what the content
> of the file is. It's only job is to inject the parameters into the action.
> (*Chris*)
>
> On Fri, Sep 4, 2009 at 1:24 PM, Bill Bohnenberger <bill98122@gmail.com
> >wrote:
>
> > Thanks, Chris, but I don't think that's the problem. I have another jsp
> > page
> > and associated action that uploads .jpg and .gif images ok with the same
> > variables...the only difference is that I am tying to get the fileUpload
> > interceptor to accept a *.txt file. (Sorry, I should've mentioned all
> this
> > in my original post)
> >
> > Bill
> >
> > On Fri, Sep 4, 2009 at 12:36 PM, Chris Pratt <thechrispratt@gmail.com
> > >wrote:
> >
> > > I believe the documentation is incorrect on the web. The setUpload
> > doesn't
> > > take a File object, it takes a String that is the fully qualified path
> to
> > > the temporary file created by the internal upload support of struts.
> So
> > > what you actually need is:
> > >
> > > public void setUpload(String upload)
> > > {
> > > this.upload = new File(upload);
> > > }
> > >
> > > (*Chris*)
> > >
> > > On Fri, Sep 4, 2009 at 11:40 AM, Bill Bohnenberger <
> bill98122@gmail.com
> > > >wrote:
> > >
> > > > Ok, I'm sure I must be doing something dumb here, but I can't seem to
> > > find
> > > > it. I'm have a problem uploading a simple text file... when I try to
> a
> > > file
> > > > named "test.txt", I get an action error message "File upload error:
> > > invalid
> > > > data." and all my file variables (see below) are null when the action
> > > > method
> > > > gets called.
> > > >
> > > > Here's my setup:
> > > >
> > > > Config:
> > > >
> > > > <action name="BulkUpload_*" class="com.rp.db.actions.BulkUpload"
> > > > method="{1}">
> > > > <interceptor-ref name="basicStack"/>
> > > > <interceptor-ref name="fileUpload">
> > > > <param name="maximumSize">8192000</param>
> > > > <param
> > > > name="allowedTypes">image/jpeg,image/gif,text/plain</param>
> > > > </interceptor-ref>
> > > > <interceptor-ref name="validation"/>
> > > > <interceptor-ref name="workflow"/>
> > > >
> > > > <result name="input">bulkUpload.jsp</result>
> > > > <result name="done" type="redirect">Menu_init</result>
> > > > <result name="login" type="redirect">Login_init</result>
> > > > </action>
> > > >
> > > > Relevant jsp code:
> > > >
> > > > <s:form action="BulkUpload_doCommand" method="post"
> > > > enctype="multipart/form-data">
> > > > <s:file label="Bulk File" name="upload" size="45"/>
> > > > <s:submit name="command" value="Upload File"/>
> > > > <s:submit name="command" value="Cancel"/>
> > > > </s:form>
> > > >
> > > > Action excerpts:
> > > > ...
> > > > private String uploadContentType;
> > > > private String uploadFileName;
> > > > private File upload;
> > > > ...
> > > > public void setUpload(File upload)
> > > > {
> > > > this.upload = upload;
> > > > }
> > > > public void setUploadFileName(String uploadFileName)
> > > > {
> > > > this.uploadFileName = uploadFileName;
> > > > }
> > > > public void setUploadContentType(String uploadContentType)
> > > > {
> > > > this.uploadContentType = uploadContentType;
> > > > }
> > > >
> > > > As I mentioned above, when I use this form to upload a text file
> named
> > > > "test.txt" I get the action error message "File upload error: invalid
> > > > data."
> > > > and all my "upload..." variables are null.
> > > >
> > > > Thanks,
> > > > Bill
> > > >
> > >
> >
>
Re: problem uploading a text file
Posted by Chris Pratt <th...@gmail.com>.
I guess I don't understand why the interceptor would care what the content
of the file is. It's only job is to inject the parameters into the action.
(*Chris*)
On Fri, Sep 4, 2009 at 1:24 PM, Bill Bohnenberger <bi...@gmail.com>wrote:
> Thanks, Chris, but I don't think that's the problem. I have another jsp
> page
> and associated action that uploads .jpg and .gif images ok with the same
> variables...the only difference is that I am tying to get the fileUpload
> interceptor to accept a *.txt file. (Sorry, I should've mentioned all this
> in my original post)
>
> Bill
>
> On Fri, Sep 4, 2009 at 12:36 PM, Chris Pratt <thechrispratt@gmail.com
> >wrote:
>
> > I believe the documentation is incorrect on the web. The setUpload
> doesn't
> > take a File object, it takes a String that is the fully qualified path to
> > the temporary file created by the internal upload support of struts. So
> > what you actually need is:
> >
> > public void setUpload(String upload)
> > {
> > this.upload = new File(upload);
> > }
> >
> > (*Chris*)
> >
> > On Fri, Sep 4, 2009 at 11:40 AM, Bill Bohnenberger <bill98122@gmail.com
> > >wrote:
> >
> > > Ok, I'm sure I must be doing something dumb here, but I can't seem to
> > find
> > > it. I'm have a problem uploading a simple text file... when I try to a
> > file
> > > named "test.txt", I get an action error message "File upload error:
> > invalid
> > > data." and all my file variables (see below) are null when the action
> > > method
> > > gets called.
> > >
> > > Here's my setup:
> > >
> > > Config:
> > >
> > > <action name="BulkUpload_*" class="com.rp.db.actions.BulkUpload"
> > > method="{1}">
> > > <interceptor-ref name="basicStack"/>
> > > <interceptor-ref name="fileUpload">
> > > <param name="maximumSize">8192000</param>
> > > <param
> > > name="allowedTypes">image/jpeg,image/gif,text/plain</param>
> > > </interceptor-ref>
> > > <interceptor-ref name="validation"/>
> > > <interceptor-ref name="workflow"/>
> > >
> > > <result name="input">bulkUpload.jsp</result>
> > > <result name="done" type="redirect">Menu_init</result>
> > > <result name="login" type="redirect">Login_init</result>
> > > </action>
> > >
> > > Relevant jsp code:
> > >
> > > <s:form action="BulkUpload_doCommand" method="post"
> > > enctype="multipart/form-data">
> > > <s:file label="Bulk File" name="upload" size="45"/>
> > > <s:submit name="command" value="Upload File"/>
> > > <s:submit name="command" value="Cancel"/>
> > > </s:form>
> > >
> > > Action excerpts:
> > > ...
> > > private String uploadContentType;
> > > private String uploadFileName;
> > > private File upload;
> > > ...
> > > public void setUpload(File upload)
> > > {
> > > this.upload = upload;
> > > }
> > > public void setUploadFileName(String uploadFileName)
> > > {
> > > this.uploadFileName = uploadFileName;
> > > }
> > > public void setUploadContentType(String uploadContentType)
> > > {
> > > this.uploadContentType = uploadContentType;
> > > }
> > >
> > > As I mentioned above, when I use this form to upload a text file named
> > > "test.txt" I get the action error message "File upload error: invalid
> > > data."
> > > and all my "upload..." variables are null.
> > >
> > > Thanks,
> > > Bill
> > >
> >
>
Re: problem uploading a text file
Posted by Bill Bohnenberger <bi...@gmail.com>.
Thanks, Chris, but I don't think that's the problem. I have another jsp page
and associated action that uploads .jpg and .gif images ok with the same
variables...the only difference is that I am tying to get the fileUpload
interceptor to accept a *.txt file. (Sorry, I should've mentioned all this
in my original post)
Bill
On Fri, Sep 4, 2009 at 12:36 PM, Chris Pratt <th...@gmail.com>wrote:
> I believe the documentation is incorrect on the web. The setUpload doesn't
> take a File object, it takes a String that is the fully qualified path to
> the temporary file created by the internal upload support of struts. So
> what you actually need is:
>
> public void setUpload(String upload)
> {
> this.upload = new File(upload);
> }
>
> (*Chris*)
>
> On Fri, Sep 4, 2009 at 11:40 AM, Bill Bohnenberger <bill98122@gmail.com
> >wrote:
>
> > Ok, I'm sure I must be doing something dumb here, but I can't seem to
> find
> > it. I'm have a problem uploading a simple text file... when I try to a
> file
> > named "test.txt", I get an action error message "File upload error:
> invalid
> > data." and all my file variables (see below) are null when the action
> > method
> > gets called.
> >
> > Here's my setup:
> >
> > Config:
> >
> > <action name="BulkUpload_*" class="com.rp.db.actions.BulkUpload"
> > method="{1}">
> > <interceptor-ref name="basicStack"/>
> > <interceptor-ref name="fileUpload">
> > <param name="maximumSize">8192000</param>
> > <param
> > name="allowedTypes">image/jpeg,image/gif,text/plain</param>
> > </interceptor-ref>
> > <interceptor-ref name="validation"/>
> > <interceptor-ref name="workflow"/>
> >
> > <result name="input">bulkUpload.jsp</result>
> > <result name="done" type="redirect">Menu_init</result>
> > <result name="login" type="redirect">Login_init</result>
> > </action>
> >
> > Relevant jsp code:
> >
> > <s:form action="BulkUpload_doCommand" method="post"
> > enctype="multipart/form-data">
> > <s:file label="Bulk File" name="upload" size="45"/>
> > <s:submit name="command" value="Upload File"/>
> > <s:submit name="command" value="Cancel"/>
> > </s:form>
> >
> > Action excerpts:
> > ...
> > private String uploadContentType;
> > private String uploadFileName;
> > private File upload;
> > ...
> > public void setUpload(File upload)
> > {
> > this.upload = upload;
> > }
> > public void setUploadFileName(String uploadFileName)
> > {
> > this.uploadFileName = uploadFileName;
> > }
> > public void setUploadContentType(String uploadContentType)
> > {
> > this.uploadContentType = uploadContentType;
> > }
> >
> > As I mentioned above, when I use this form to upload a text file named
> > "test.txt" I get the action error message "File upload error: invalid
> > data."
> > and all my "upload..." variables are null.
> >
> > Thanks,
> > Bill
> >
>
Re: problem uploading a text file
Posted by Chris Pratt <th...@gmail.com>.
I believe the documentation is incorrect on the web. The setUpload doesn't
take a File object, it takes a String that is the fully qualified path to
the temporary file created by the internal upload support of struts. So
what you actually need is:
public void setUpload(String upload)
{
this.upload = new File(upload);
}
(*Chris*)
On Fri, Sep 4, 2009 at 11:40 AM, Bill Bohnenberger <bi...@gmail.com>wrote:
> Ok, I'm sure I must be doing something dumb here, but I can't seem to find
> it. I'm have a problem uploading a simple text file... when I try to a file
> named "test.txt", I get an action error message "File upload error: invalid
> data." and all my file variables (see below) are null when the action
> method
> gets called.
>
> Here's my setup:
>
> Config:
>
> <action name="BulkUpload_*" class="com.rp.db.actions.BulkUpload"
> method="{1}">
> <interceptor-ref name="basicStack"/>
> <interceptor-ref name="fileUpload">
> <param name="maximumSize">8192000</param>
> <param
> name="allowedTypes">image/jpeg,image/gif,text/plain</param>
> </interceptor-ref>
> <interceptor-ref name="validation"/>
> <interceptor-ref name="workflow"/>
>
> <result name="input">bulkUpload.jsp</result>
> <result name="done" type="redirect">Menu_init</result>
> <result name="login" type="redirect">Login_init</result>
> </action>
>
> Relevant jsp code:
>
> <s:form action="BulkUpload_doCommand" method="post"
> enctype="multipart/form-data">
> <s:file label="Bulk File" name="upload" size="45"/>
> <s:submit name="command" value="Upload File"/>
> <s:submit name="command" value="Cancel"/>
> </s:form>
>
> Action excerpts:
> ...
> private String uploadContentType;
> private String uploadFileName;
> private File upload;
> ...
> public void setUpload(File upload)
> {
> this.upload = upload;
> }
> public void setUploadFileName(String uploadFileName)
> {
> this.uploadFileName = uploadFileName;
> }
> public void setUploadContentType(String uploadContentType)
> {
> this.uploadContentType = uploadContentType;
> }
>
> As I mentioned above, when I use this form to upload a text file named
> "test.txt" I get the action error message "File upload error: invalid
> data."
> and all my "upload..." variables are null.
>
> Thanks,
> Bill
>