cancel
Showing results for 
Search instead for 
Did you mean: 

FileUpload and AbstractPortalComponent

Former Member
0 Kudos

The following does not seem to find a valid file to upload and isFileParam always returns false. I am using AbstractPortalComponent and the example sin SDN seem to use PageProcessorComponent.

myContext = 
PageContextFactory.createPageContext(request, response);
Event lastEvent = myContext.getCurrentEvent();
if (lastEvent != null) {
	if (lastEvent.getComponentName().equals("submit")) {
	if (myContext.isFileParam("fileUpload"))
		response.write("yep, it's a file parameter");
	else
		response.write("not a file param");
//
//
//
FileUpload file = new FileUpload("fileUpload");
file.setAccept("text/xml");
file.setSize(50);
Label label = new Label("Select XML file with assignments");
gl.addComponent(1, 1, label);
gl.addComponent(1, 2, file);

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

OK, I am now reading files OK, but only if they are visible to the portal. For example, if I do a fileupload of c:\somewhere\a.xml everything works OK, but if I browse to y:\somewhere\a.xml, I have problems. I think this is because the J2EE engine doesn't know about y:. I am using BufferedReader.

How can I read a file from the client browser based on a filename that has been entered by FileUpload?

Thanks

Former Member
0 Kudos

Hi Michael,

Can you post your code. I use the following and it works for me.

//get the file
FileUpload rimage = (FileUpload) getComponentByName("imagefile");
if (rimage.getFile() != null) {
 String mimetype = rimage.getFile().getContentType();
 String resource = rimage.getFile().getFileName();
try {
    FileInputStream sourceFileInput = new FileInputStream(rimage.getFile().getFile().getAbsolutePath());
    } catch (Exception e) {
	 e.printStackTrace(); }
}

Answers (2)

Answers (2)

Former Member
0 Kudos

The FileInputStream was just what I needed!

Former Member
0 Kudos

Hi Michael,

Can you post your complete code because the code you have posted doesn't tell us anything. I think you are missing the following lines.

Form myForm = myContext.createFormDocument("myform");
//this line is very important
<b>myForm.setEncodingType("multipart/form-data");</b> 

PS: Please reward points if the problem is resolved or the answer is helpful.

Former Member
0 Kudos

I had that code in, but it still didn't work so I gave up and rewrote as a DynPage...