• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing an object to a Browser  RSS feed

 
milan doshi
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,

I have an object that needs to be streamed into an image.I know how to read an Image from a System folder and pass it as an image in the output. Now my requirement is how should I pass the the image (in form of an object) to the browser.

My code for reading the the image from the file structure is as follows:
ServletOutputStream out = response.getOutputStream();
File file = new File("C:\\JakartaTomcat4.1.27\\jakarta-tomcat-4.1.27\\webapps\\UW\\image1.jpeg");
response.setContentType("image/jpeg");
response.setHeader("Content-Disposition","inline");

FileInputStream in = new FileInputStream(file);
byte[] bytes = new byte[10000];
// Read in file and at the same time write the stream to the resposne.
while (true) {
int count = in.read(bytes);
if (count == -1)
break;
out.write(bytes, 0, count);
}

By The Way, My object is of type org.apache.axis.attachments.AttachmentPart

Thanks in advance,
Milan
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A browser isn't going to know what to do with an org.apache.axis.attachments.AttachmentPart object.
 
milan doshi
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well,

Maybe I was not very clear with the Question. My object (is an attachement object) and I can determine its Mime Type etc.

I can also send it (as an image) to a folder structure as follows:

if (segment.getEncodedData() instanceof AttachmentPart) {
AttachmentPart part = (AttachmentPart)segment.getEncodedData();
FileOutputStream out = null;
try {
System.out.println(j+") PhotocopyImmediateService.parseImmediateServiceResponse: About to create the OutputStream");
out = new FileOutputStream("d:/temp/Image"+j+"."+segment.getProperties().getCompressionFormatCode());
part.getDataHandler().writeTo(out);
out.close();
} catch (Exception e) {
throw new IVSXMLException(txid,"","");
}
}

Instead, I want to stream it to a Browser(from a Servlet). How do I achieve it?

Thanks in advance,
Milan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!