aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes DecodingException when Downloading Attachment. Please advise me how to fix? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "DecodingException when Downloading Attachment. Please advise me how to fix?" Watch "DecodingException when Downloading Attachment. Please advise me how to fix?" New topic
Author

DecodingException when Downloading Attachment. Please advise me how to fix?

Sergey Kargopolov
Ranch Hand

Joined: Jul 04, 2003
Posts: 63
Hi!

I am getting an Error message when downloading attachment from Gmail. Any image file that I download throws com.sun.mail.util.DecodingException:

com.sun.mail.util.DecodingException: BASE64Decoder: Error in encoded stream: needed 4 valid base64 characters but only got 3 before EOF, the 10 most recent characters were: "rOLsVOnCzb"

Even though an Exception is thrown downloaded file can be opened and viewed. But not good for scaling...

Please advise me what can I do to download file without DecodingException?

Thank you!


InputStream input = bodyPart.getInputStream()
String fileName = bodyPart.getFileName();

FileOutputStream fos = new FileOutputStream(fileName);
BufferedOutputStream bos = new BufferedOutputStream(fos);
BufferedInputStream bis = new BufferedInputStream(input);

byte buf[]=new byte[1024];
int aByte;
try
{
while ((aByte = bis.read(buf)) >0) {
bos.write(buf,0,aByte);
}

} catch(Exception ex)
{
ex.printStackTrace();
} finally{
bos.flush();
bos.close();
bis.close();
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DecodingException when Downloading Attachment. Please advise me how to fix?
 
Similar Threads
when streaming doc ciontent to browser, multiple IE File Download prompts displayed
File Download problem using icefaces
saving attachments with javamail
How to read and write excel file
JavaMail 1.2 API - Out Of Memory Error when number of attachments to be downloaded is