On Mon, 13 Jan 2003 23:30:42 -0800 (PST), Henrik Westergaard Hansen wrote:
>
> >
> Hello,
> Maybe this discussion thread can help me. I would be greaty appreciated.
>
> I cant get FileItem.write(String file) to work. I throws an
> FileNotFoundException: GIF89a (something binary);
> (The filename, directory name, or volume label syntax is incorrect)
>
> The scenario is the following:
>
> Having the following action:
> public void doUploadbanner(RunData data, Context context) {
> ParameterParser params = data.getParameters();
> try {
> FileItem fi = null;
> fi = params.getFileItem("uploadfile");
> if (fi != null) {
> String content = fi.getString();
> fi.write(content);
> }
>
<snip>
Henrik, the problem here is the following: The getString() method returns the
contents of the file as a string, so the gif89a in your error message indicates
to me that you have been uploading a gif-file. The fi.write() takes the file
name as the parameter, and then you can see how you can end up in trouble with
your code... The fi.getFileName() returns the original filename with complete
path. I suggest you do something like the following:
String filename = fi.getFileName();
// Assuming the file was from a Win-post:
int pos = filename.lastIndexOf('\\');
filename = filename.subString(pos + 1);
fi.write( somePathWhereYouWantFiles + "/" + filename );
Hope this helps!
Harald
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>