• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problems with WOFileUpload over DirectAction and large files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems with WOFileUpload over DirectAction and large files


  • Subject: Problems with WOFileUpload over DirectAction and large files
  • From: Adam Czysciak <email@hidden>
  • Date: Thu, 5 Jan 2006 15:24:56 +0100

Hi,

I use WebObjects 5.2.3. In my component I have:

Form2: WOForm {
enctype = "multipart/form-data";
multipleSubmit = false;
name = "form1";
onSubmit = "return onSubmit();";
directActionName = "fileUpload";
}

and:

FileUpload2: WOFileUpload {
filePath = originalFileName;
finalFilePath = tempFileName;
streamToFilePath = tempPath;
name = "FileChooser";
}

then, in my DirectAction I simply stream this data to my file:

public WOActionResults fileUploadAction() {
System.out.println("**** file upload action");


try {
com.webobjects.appserver._private.WOInputStreamData isd =
(com.webobjects.appserver._private.WOInputStreamData) request.formValueForKey("FileChooser");

InputStream is = isd.stream();

File tempFile = File.createTempFile("upload.da.", ".tmp", tmpFilesPath);
FileOutputStream fos = new FileOutputStream(tempFile);


int fileLength = 0;
byte buf[] = new 65536];
while (is.available() > 0) {
int k = is.read(buf);
if (k < 0) continue;
fos.write(buf, 0, k);
fileLength += k;
}
fos.close();
is.close();

Well, generally it works. I'm aware that perhaps using WOInputStreamData is not the way to go, but this was the only example I've found... But now my problem appears - it looks that using this stream loads the data into memory. I started uploading 400 MB file, got the debug message and then memory usage started growing very fast (checked with 'top'), which can lead to OutOfMemoryError.

Any ideas how to prevent loading the file into memory? Or maybe any other better solution for streamed DA file uploads? I didn't find it in Practical WebObjects...


BTW - I also use this code fragment to get the filename - is it the proper usage? is it always componentID + ".filename" ?

String filename = request.stringFormValueForKey("FileChooser.filename");



Thanks in advance,
--
Regards,
Adam Czysciak
email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: Frameworks and versioning
  • Next by Date: Re: Frameworks and versioning
  • Previous by thread: Having Problems Running Java Apps
  • Next by thread: WOToOneRelationship and "dirty" editing context
  • Index(es):
    • Date
    • Thread