Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

Sergey Kargopolov
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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;
while ((aByte = >0) {

} catch(Exception ex)
} finally{
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic