Skip to Content
author's profile photo Former Member
Former Member

FileUpload and AbstractPortalComponent

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);

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 20, 2005 at 10:04 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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(); }
      }

  • author's profile photo Former Member
    Former Member
    Posted on May 04, 2005 at 11:14 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 21, 2005 at 06:18 AM

    The FileInputStream was just what I needed!

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.