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

FileUpload problem: InputStream does not contain a serialized object

Hi All,

I'm using the FileUpload component in a JSPDynPage and the htmlb component seems to work fine but I cannot read the file (InputStream). I get the following error(IOException): "InputStream does not contain a serialized object".

Please let me know what is wrong with my code. This is a part of the code I used:

public FileInputStream sourceFileInput;
public ObjectInputStream input;

FileUpload fu;
fu = (FileUpload) this.getComponentByName("myFileUpload");

IFileParam fileParam = ((FileUpload) getComponentByName("myFileUpload")).getFile();

File f       = fileParam.getFile();
file         = fu.getFile().getFile();
absolutepath = fu.getFile().getFile().getAbsolutePath();

this.sourceFileInput = new FileInputStream(file);
input = new ObjectInputStream(sourceFileInput);

The last line of code seems to generate te error.

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 06, 2005 at 08:16 AM

    Hi,

    I used the FileUpload component to store files from the client to CM so when I read the file I was able to read from a FileInputStream straight into a byte array. I'm not sure if this will be any help to you since I don't know what you're doing with the file once uploaded but here is some code;

    <code>

    FileUpload fu = (FileUpload)this.getComponentByName("myFileUpload");

    if(fu!=null){

    __IFileParam fileParam = fu.getFile();

    __if(fileParam!=null){

    ____File f = fileParam.getFile();

    ____if(f!=null){

    ______FileInputStream fis = new FileInputStream(f);

    ______byte[] bytes = new byte[(int)f.length()];

    ______fis.read(bytes);

    ______...

    ______...

    ____}

    __}

    }

    </code>

    This read the file contents into the byte array.

    SinceI was writing the file as a resource into CM I was able then to write;

    <code>

    IContent aContent = new Content(new ByteArrayInputStream(bytes), fileParam.getContentType(), (int)f.length());

    </code>

    and then store it as a resource in the CM.

    I hope it helps.

    P.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Detlev Beutner

      Hi,

      I have found the answers, thank you both.

      (I included the examle code. Perhaps of some use to someone.)

      FileUpload fu;
      fu = null;
      fu = (FileUpload) this.getComponentByName("myFileUpload");
      //	  this is the temporary file
      if (fu != null) {
      	IFileParam fileParam = ((FileUpload) getComponentByName("myFileUpload")).getFile();
      	if (fileParam != null) {
      		// get info about this file and create a FileInputStream
      		File f = fileParam.getFile();
      		if (f != null) {
      			try {
      				fis = new FileInputStream(f);
      			}
      			// process exceptions opening files
      			catch (FileNotFoundException ex) {
      				myBean.setMessage(
      					"1" + f + ex.getLocalizedMessage());
      			}
      			isr = new InputStreamReader(fis);
      			br = new BufferedReader(isr);
      		}
      	}
      }
      String textLine = "";
      
      do {
      	try {
      		textLine = (String) br.readLine();
      	} catch (IOException e) {
      		myBean.setMessage(
      			"1" + e.getLocalizedMessage());
      	};
      	// Jco append table & put data into the record 
      	// (I_FILE is the table with txt data that is sent to the RFC)
      	I_FILE.appendRow();	
      	I_FILE.setValue(textLine, "REC");						
      } while (textLine != null);
      

  • Posted on Jan 06, 2005 at 09:58 AM

    Hi Raymond,

    the problem is the last line. An ObjectInputStream is for reading serialized java objects, see http://java.sun.com/j2se/1.4.2/docs/api/java/io/ObjectInputStream.html

    So just use the sourceFileInput to read from, as Patrick has stated.

    Hope it helps

    Detlev

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 06, 2005 at 11:43 AM

    FileOutputStream has a write(byte[] b) method, give it a go and see how it turns out. I'm working on a different project (different place) just now and don't have access to that code so I can't run the test myself.

    Let us know how it goes.

    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.