Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
New Developer
Posts: 2
Registered: ‎09-20-2009
My Device: Not Specified

Problem Retrieving Attachment Contents

Hi,

 

My application needs to be able to download attachments from email messages selected and save them to the SD card.  I'm able to get the message body part with the attachment from the mail store, but I'm not able to get the attachment content.  All attachment types come back as UnsupportedAttachmentPart, and despite having attachment.hasMore() = true and calling Transport.more(attachment, true) to download the data from the server, the data size (attachment.GetSize()) is always zero.  The attachments I've tested this on are .jpg and .pdf, which both show up as an unsupported type.

 

Questions:

- Can you actually download the content of an UnsupportedAttachmentPart, or will the file size always be zero?

- If you can not download UnsupportedAttachmentPart, then do you need to create an AttachmentHandler to make it supported?  I don't want to work with custom file types, I'm just want to save the content of standard types to the file system

- I've seen a lot of posts refer to prefixing file names with x-rimdevice: my application will not have control over filenames, can I download attachments without this file name prefix 

 

Developing for Blackberry 8310 on v4.5.

 

Code sample below:

 

 

private void downloadAttachment(Message msg) { Multipart mp = (Multipart) msg.getContent(); //Try and get the attachments Object obj = stripAttachment(mp); //Returns vector of attachments Vector attachmentList = new Vector(); //Test if I got any attachments back if(!obj.equals(null)) { if(obj instanceof Vector) { attachmentList = (Vector)obj; for (Enumeration e = attachmentList.elements(); e.hasMoreElements();) { Object attachObj = e.nextElement(); if (attachObj instanceof SupportedAttachmentPart) { //This is a supported attachment. SupportedAttachmentPart attachment = (SupportedAttachmentPart)attachObj; if(attachment.hasMore()) { Status.show("There's more data for the attachment on the server - Try to get..."); try { Transport.more(attachment, true);} catch (MessagingException ex) { Status.show("Error: " + ex.getMessage()); } } Object attachData = attachment.getContent(); if(!attachData.equals(null)) { byte[] data = (byte[])attachData; String filename = attachment.getFilename(); Status.show("Attempting to write to SD card (supported attachment type)..."); Status.show("Filename: " + filename + ", Size: " + attachment.getSize()); this.writeAttachment(data,filename); } } else if (attachObj instanceof UnsupportedAttachmentPart) { //This is an unsupported attachment. UnsupportedAttachmentPart attachment = (UnsupportedAttachmentPart)attachObj; if(attachment.hasMore()) { Status.show("There's more data for the attachment on the server - Try to get..."); try { Transport.more(attachment, true);} catch (MessagingException ex) { Status.show("Error: " + ex.getMessage()); } } Object attachData = attachment.getContent(); if(!attachData.equals(null)) { byte[] data = (byte[])attachData; String filename = attachment.getName(); Status.show("Attempting to write to SD card (unsupported attachment type)..."); Status.show("Filename: " + filename + ", Size: " + attachment.getSize()); Status.show("Data length: " + data.length); this.writeAttachment(data,filename); } } } } } }

 


 

BlackBerry Development Advisor
Posts: 15,813
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Problem Retrieving Attachment Contents

This link should answer your questions.

 

What Is - Delivering attachment contents to a BlackBerry smartphone
Article Number: DB-00475

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.