Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

File Upload example has limit of 2048 bytes

tnologySep 29 2011 — edited Oct 5 2011
I am following an example on how to perform a file upload from a JSF page in Frank Nimphius's book: Oracle Fusion Developer Guide
I have entered the exact code from Chapter 12, pages 400-401 and also added to my web.xml the
oracle.adf.view.rich.webapp.AdfFacesFilter and the org.apache.myfaces.trinidad.webapp.TrinidadFilter
I also added context-params for:
org.apache.myfaces.trinidad.UPLOAD_MAX_MEMORY
org.apache.myfaces.trinidad.UPLOAD_MAX_DISK_SPACE
org.apache.myfaces.trinidad.UPLOAD_TEMP_DIR
to increase these buffer sizes.

The problem I am having is that my uploaded file is always corrupt, the entire contents of the file are not fully uploaded even though the file size of the uploaded file says it's the full size.
I can tell this because I tried uploading a text file and I only get a few lines of text and not the entire contents of the file.

By adding a few debug printouts to my file upload method, I discovered that the java.io.InputStream.read(buffer) stops reading at 2048 bytes. I can't figure out why?!
Below is the file upload method from my backing bean:

public String uploadAttachmentButton() {
UploadedFile myAttachment = this.getAttachment();
FacesContext fctx = FacesContext.getCurrentInstance();
FacesMessage message;

try{
System.out.println(">> Attachment: " + myAttachment.getFilename());
String strWriteFilePath = "c:\\Downloads\\test\\" + myAttachment.getFilename();
PrintStream newFile = new PrintStream( strWriteFilePath );
InputStream inStream = myAttachment.getInputStream();
long length = myAttachment.getLength();
System.out.println(">> Attachment size: " + length );
byte[] buffer = new byte[(int)length];
System.out.println(">> Buffer size: " + buffer.length );
System.out.println(">> InputStream size: " + inStream.read(buffer) );
newFile.write(buffer);
newFile.close();
message = new FacesMessage("Successfully uploaded attachment " + myAttachment.getFilename() );
} catch (Exception e) {
//System.out.println("Attachment Upload Error: " + e.getMessage() );
e.printStackTrace();
message = new FacesMessage("Invalid Attachment, try again!");
}
fctx.addMessage(null, message);
return null;
}

Here is a sample printout from my console:
Attachment: IMG_2147.jpg
Attachment size: 1764829
Buffer size: 1764829
InputStream size: 2048
Does anyone know why InputStream can only read 2048 bytes?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 2 2011
Added on Sep 29 2011
12 comments
10,127 views