You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by elyes sallem <el...@gmail.com> on 2008/12/16 12:24:15 UTC
get file path from FormFile
Hello,
after publishing this question, i conclude that it is not possible de get
back the absolute path from FormFile
but the problem is that i import a jar file, in which i call a method that
accept only path of file
so what do you propose, i get the inputstream , then i create temporarly a
file and i delete it at the end
or you have an other ideai?
Thanks
Regards
Elyes.
Re: get file path from FormFile
Posted by Dave Newton <ne...@yahoo.com>.
--- On Tue, 12/16/08, elyes sallem wrote:
> to avoid any confusion,
Too late!
> 1- i have data in a file, so through the formfile, i get
> the file path (now i make the test locally, but after it
> will be deployed on a server) and i load this data in a
> database, depending on the file's meta data, and its
> content
The file name in the FormFile is the file name from the *client*--NOT the local path on the application server.
In your case, since you're testing locally, it *is* the file path on the client--but only because the browser you're using includes the complete path. Not all browsers do; some will only give the filename. Please take this in to account.
> now i have to make some choices of loading the file , and
> saving the excel file
By using the servlet example given, or the same thing but in an action (and returning null) the *browser* will give you the option to open or save the file. *You* don't code that.
I really think you should search the web for "struts +file download" or something similar; it seems like there are some fundamental web application things that might be helpful to know.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: get file path from FormFile
Posted by elyes sallem <el...@gmail.com>.
ok, for the upload, i saved the file on the server
so i create a tmp file in this directory
"servlet.getServletContext().getRealPath("/")"
is it ok for the place , or i must create temporary file in an other
location? if not OK, where do i have to create them?
Thanks
Regards
Elyes
2008/12/16 Nils-Helge Garli Hegvik <ni...@gmail.com>
> So... are you:
>
> 1) Trying to upload a file to the server?
> 2) Trying to send a file the browser?
> 3) Both?
>
> If 1) See if http://wiki.apache.org/struts/StrutsFileUpload can help.
> If your API only accepts a file path, save the file as a temp file
> locally on the server.
> If 2) The solution has been provided to you in your previous thread:
> Stream the file content to the browser.
> If 3) See 1) and 2)
>
> Nils-H
>
> On Tue, Dec 16, 2008 at 2:09 PM, elyes sallem <el...@gmail.com>
> wrote:
> > to avoid any confusion,
> > all i want to do is that :
> > 1- i have data in a file, so through the formfile, i get the file path
> (now
> > i make the test locally, but after it will be deployed on a server) and i
> > load this data in a database, depending on the file's meta data, and its
> > content
> > 2- i allow the user to make some select , with some condition
> > after setting his condition, through the interface (in the final it is a
> > select with conditions ...)
> > i allow the user to exports this data in an excel file
> > that's all
> > the trt of parsing the file metadata, and content , is done
> > the trt of export data in an excel file based on a select is done
> > now i have to make some choices of loading the file , and saving the
> excel
> > file
> > i wish that it was clear
> > furthermore,
> > yes Dave , this is my proposition
> > have you a better idea?
> > as for the proposition to use servlet link, it was not clear
> >
> > Regards
> > Elyes
> >
> >
> > 2008/12/16 Dave Newton <ne...@yahoo.com>
> >
> >> --- On Tue, 12/16/08, elyes sallem wrote:
> >> > this library, take as input a file and depending on this
> >> > file's metadata generates tables in a database and make trt
> >> > after this (so as a constraint, i can't modify the class in
> >> > this jar)
> >>
> >> So... you're *uploading* a file to the server (from the user of the
> browser
> >> to the web application)??? Then you need to save the FormFile locally
> and
> >> use *that* path when you call your library methods.
> >>
> >> Dave
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> >
> > --
> > Elyes.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Elyes.
Re: get file path from FormFile
Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
So... are you:
1) Trying to upload a file to the server?
2) Trying to send a file the browser?
3) Both?
If 1) See if http://wiki.apache.org/struts/StrutsFileUpload can help.
If your API only accepts a file path, save the file as a temp file
locally on the server.
If 2) The solution has been provided to you in your previous thread:
Stream the file content to the browser.
If 3) See 1) and 2)
Nils-H
On Tue, Dec 16, 2008 at 2:09 PM, elyes sallem <el...@gmail.com> wrote:
> to avoid any confusion,
> all i want to do is that :
> 1- i have data in a file, so through the formfile, i get the file path (now
> i make the test locally, but after it will be deployed on a server) and i
> load this data in a database, depending on the file's meta data, and its
> content
> 2- i allow the user to make some select , with some condition
> after setting his condition, through the interface (in the final it is a
> select with conditions ...)
> i allow the user to exports this data in an excel file
> that's all
> the trt of parsing the file metadata, and content , is done
> the trt of export data in an excel file based on a select is done
> now i have to make some choices of loading the file , and saving the excel
> file
> i wish that it was clear
> furthermore,
> yes Dave , this is my proposition
> have you a better idea?
> as for the proposition to use servlet link, it was not clear
>
> Regards
> Elyes
>
>
> 2008/12/16 Dave Newton <ne...@yahoo.com>
>
>> --- On Tue, 12/16/08, elyes sallem wrote:
>> > this library, take as input a file and depending on this
>> > file's metadata generates tables in a database and make trt
>> > after this (so as a constraint, i can't modify the class in
>> > this jar)
>>
>> So... you're *uploading* a file to the server (from the user of the browser
>> to the web application)??? Then you need to save the FormFile locally and
>> use *that* path when you call your library methods.
>>
>> Dave
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> --
> Elyes.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: get file path from FormFile
Posted by elyes sallem <el...@gmail.com>.
to avoid any confusion,
all i want to do is that :
1- i have data in a file, so through the formfile, i get the file path (now
i make the test locally, but after it will be deployed on a server) and i
load this data in a database, depending on the file's meta data, and its
content
2- i allow the user to make some select , with some condition
after setting his condition, through the interface (in the final it is a
select with conditions ...)
i allow the user to exports this data in an excel file
that's all
the trt of parsing the file metadata, and content , is done
the trt of export data in an excel file based on a select is done
now i have to make some choices of loading the file , and saving the excel
file
i wish that it was clear
furthermore,
yes Dave , this is my proposition
have you a better idea?
as for the proposition to use servlet link, it was not clear
Regards
Elyes
2008/12/16 Dave Newton <ne...@yahoo.com>
> --- On Tue, 12/16/08, elyes sallem wrote:
> > this library, take as input a file and depending on this
> > file's metadata generates tables in a database and make trt
> > after this (so as a constraint, i can't modify the class in
> > this jar)
>
> So... you're *uploading* a file to the server (from the user of the browser
> to the web application)??? Then you need to save the FormFile locally and
> use *that* path when you call your library methods.
>
> Dave
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Elyes.
Re: get file path from FormFile
Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
Ah...finally someone cracked the code!
Nils-H
On Tue, Dec 16, 2008 at 1:55 PM, Dave Newton <ne...@yahoo.com> wrote:
> --- On Tue, 12/16/08, elyes sallem wrote:
>> this library, take as input a file and depending on this
>> file's metadata generates tables in a database and make trt
>> after this (so as a constraint, i can't modify the class in
>> this jar)
>
> So... you're *uploading* a file to the server (from the user of the browser to the web application)??? Then you need to save the FormFile locally and use *that* path when you call your library methods.
>
> Dave
>
>
> ---------------------------------------------------------------------
> 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: get file path from FormFile
Posted by Dave Newton <ne...@yahoo.com>.
--- On Tue, 12/16/08, elyes sallem wrote:
> this library, take as input a file and depending on this
> file's metadata generates tables in a database and make trt
> after this (so as a constraint, i can't modify the class in
> this jar)
So... you're *uploading* a file to the server (from the user of the browser to the web application)??? Then you need to save the FormFile locally and use *that* path when you call your library methods.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: get file path from FormFile
Posted by elyes sallem <el...@gmail.com>.
this library, take as input a file and depending on this file's metadata
generates tables in a database and make trt after this (so as a constraint,
i can't modify the class in this jar)
Regards
Elyes
2008/12/16 Nils-Helge Garli Hegvik <ni...@gmail.com>
> What library (jar) is this? I assume that you mean that this library
> generates the actual file content that you want to send back to the
> browser? As you suggest, one way is to create a temp file which you
> read and stream back to the browser. Or you could save the file in a
> public area where it can be downloaded by the user.
>
> Nils-H
>
> On Tue, Dec 16, 2008 at 12:24 PM, elyes sallem <el...@gmail.com>
> wrote:
> > Hello,
> > after publishing this question, i conclude that it is not possible de get
> > back the absolute path from FormFile
> > but the problem is that i import a jar file, in which i call a method
> that
> > accept only path of file
> > so what do you propose, i get the inputstream , then i create temporarly
> a
> > file and i delete it at the end
> > or you have an other ideai?
> >
> > Thanks
> > Regards
> > Elyes.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
Elyes.
Re: get file path from FormFile
Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
What library (jar) is this? I assume that you mean that this library
generates the actual file content that you want to send back to the
browser? As you suggest, one way is to create a temp file which you
read and stream back to the browser. Or you could save the file in a
public area where it can be downloaded by the user.
Nils-H
On Tue, Dec 16, 2008 at 12:24 PM, elyes sallem <el...@gmail.com> wrote:
> Hello,
> after publishing this question, i conclude that it is not possible de get
> back the absolute path from FormFile
> but the problem is that i import a jar file, in which i call a method that
> accept only path of file
> so what do you propose, i get the inputstream , then i create temporarly a
> file and i delete it at the end
> or you have an other ideai?
>
> Thanks
> Regards
> Elyes.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: get file path from FormFile
Posted by Robert Graf-Waczenski <rg...@lsoft.com>.
Looking at your previous posts, i think that you are wasting your time
even thinking about using a java applet. Go back a few steps and think
again, maybe answering the following simple sequence of questions:
1) Your web application server has access to some data somewhere. The
data can be anything, let's call the data "Blurb".
2) You want to allow your users to export "Blurb" from your web server
to a file.
3) The file name shall be supplied by the user via a standard "Save As"
dialog.
4) After the user has chosen the file, "Blurb" is saved in the file.
This is a download link, plain and simple, i.e. a link that points to a
servlet url (see my example earlier) or (as you prefer it) an action url
(see another post in your previous thread on how to accomplish the same
thing with a struts action). If you follow my example, then you get
*EXACTLY* the behavior you desire. No applet. No fumbling around with
FormFile properties. No file upload.
Robert
elyes sallem wrote:
> Hello,
> after publishing this question, i conclude that it is not possible de get
> back the absolute path from FormFile
> but the problem is that i import a jar file, in which i call a method that
> accept only path of file
> so what do you propose, i get the inputstream , then i create temporarly a
> file and i delete it at the end
> or you have an other ideai?
>
> Thanks
> Regards
> Elyes.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: get file path from FormFile
Posted by "Givler, Eric" <eg...@state.pa.us>.
I wasn't making a change. I just introduced a class in that package so that I could access the CommonsFormFile class inside of CommonsMultipartRequestHandler. I called it: CommonsFileHelper. The reason I was using it was that the file was already uploaded, AND in the O/S, so I figured, why copy it again, especially if it's big - it just adds another step.
-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com]
Sent: Wednesday, December 17, 2008 12:52 PM
To: Struts Users Mailing List
Subject: RE: get file path from FormFile
It hardly seems necessary to make a framework change when you can just write the file.
--- On Wed, 12/17/08, Givler, Eric <eg...@state.pa.us> wrote:
> From: Givler, Eric <eg...@state.pa.us>
> Subject: RE: get file path from FormFile
> To: "'Struts Users Mailing List'" <us...@struts.apache.org>
> Date: Wednesday, December 17, 2008, 10:34 AM
> Would there be an issue with modifying the controller settings and
> setting the memFileSize artifically low so the file is always written
> to disk, then gaining access to the filename via reflection?
>
> // create in package org.apache.struts.upload
> public static String getFilePath( FormFile file ) {
> String path = null;
> Class
> formClass=CommonsMultipartRequestHandler.CommonsFormFile.class;
> Field fileItemField = formClass.getDeclaredField("fileItem");
> fileItemField.setAccessible(true);
> Object o = fileItemField.get( file );
> if ( o instanceof DefaultFileItem ) {
> DefaultFileItem df = (DefaultFileItem) o;
> File osFile = df.getStoreLocation();
> path = osFile.getPath();
> }
> return path;
> }
>
>
> -----Original Message-----
> From: elyes sallem [mailto:elyes.sallem@gmail.com]
> Sent: Tuesday, December 16, 2008 6:24 AM
> To: Struts Users Mailing List
> Subject: get file path from FormFile
>
>
> Hello,
> after publishing this question, i conclude that it is not possible de
> get back the absolute path from FormFile but the problem is that i
> import a jar file, in which i call a method that accept only path of
> file so what do you propose, i get the inputstream , then i create
> temporarly a file and i delete it at the end or you have an other
> ideai?
>
> Thanks
> Regards
> Elyes.
>
> ---------------------------------------------------------------------
> 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
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: get file path from FormFile
Posted by Dave Newton <ne...@yahoo.com>.
It hardly seems necessary to make a framework change when you can just write the file.
--- On Wed, 12/17/08, Givler, Eric <eg...@state.pa.us> wrote:
> From: Givler, Eric <eg...@state.pa.us>
> Subject: RE: get file path from FormFile
> To: "'Struts Users Mailing List'" <us...@struts.apache.org>
> Date: Wednesday, December 17, 2008, 10:34 AM
> Would there be an issue with modifying the controller
> settings and setting the memFileSize artifically low so the
> file is always written to disk, then gaining access to the
> filename via reflection?
>
> // create in package org.apache.struts.upload
> public static String getFilePath( FormFile file ) {
> String path = null;
> Class
> formClass=CommonsMultipartRequestHandler.CommonsFormFile.class;
> Field fileItemField =
> formClass.getDeclaredField("fileItem");
> fileItemField.setAccessible(true);
> Object o = fileItemField.get( file );
> if ( o instanceof DefaultFileItem ) {
> DefaultFileItem df = (DefaultFileItem) o;
> File osFile = df.getStoreLocation();
> path = osFile.getPath();
> }
> return path;
> }
>
>
> -----Original Message-----
> From: elyes sallem [mailto:elyes.sallem@gmail.com]
> Sent: Tuesday, December 16, 2008 6:24 AM
> To: Struts Users Mailing List
> Subject: get file path from FormFile
>
>
> Hello,
> after publishing this question, i conclude that it is not
> possible de get back the absolute path from FormFile but the
> problem is that i import a jar file, in which i call a
> method that accept only path of file so what do you propose,
> i get the inputstream , then i create temporarly a file and
> i delete it at the end or you have an other ideai?
>
> Thanks
> Regards
> Elyes.
>
> ---------------------------------------------------------------------
> 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: get file path from FormFile
Posted by "Givler, Eric" <eg...@state.pa.us>.
Would there be an issue with modifying the controller settings and setting the memFileSize artifically low so the file is always written to disk, then gaining access to the filename via reflection?
// create in package org.apache.struts.upload
public static String getFilePath( FormFile file ) {
String path = null;
Class formClass=CommonsMultipartRequestHandler.CommonsFormFile.class;
Field fileItemField = formClass.getDeclaredField("fileItem");
fileItemField.setAccessible(true);
Object o = fileItemField.get( file );
if ( o instanceof DefaultFileItem ) {
DefaultFileItem df = (DefaultFileItem) o;
File osFile = df.getStoreLocation();
path = osFile.getPath();
}
return path;
}
-----Original Message-----
From: elyes sallem [mailto:elyes.sallem@gmail.com]
Sent: Tuesday, December 16, 2008 6:24 AM
To: Struts Users Mailing List
Subject: get file path from FormFile
Hello,
after publishing this question, i conclude that it is not possible de get back the absolute path from FormFile but the problem is that i import a jar file, in which i call a method that accept only path of file so what do you propose, i get the inputstream , then i create temporarly a file and i delete it at the end or you have an other ideai?
Thanks
Regards
Elyes.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: get file path from FormFile
Posted by Dave Newton <ne...@yahoo.com>.
--- On Tue, 12/16/08, elyes sallem wrote:
> after publishing this question, i conclude that it is not
> possible de get back the absolute path from FormFile but
> the problem is that i import a jar file, in which i call
> a method that accept only path of file so what do you propose,
> i get the inputstream , then i create temporarly a file and
> i delete it at the end or you have an other ideai?
What, exactly, are you trying to do?
I thought you were creating a result stream that you wanted the client to be able to download: a normal web application download.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org