1
votes

I am using Gmail API on Android and I have a problem for file attachment.

I followed example below: https://developers.google.com/gmail/api/guides/sending#creating_messages_with_attachments

and the problem is arisen here:

String encodedEmail = Base64.encodeBase64URLSafeString(bytes.toByteArray());

I want to attach a video file about 8MB, but this line shows 'out of memory' error.

It is okay when I send image file attachment. (Typically below 1MB).

How can I deal with it?

1
How did you solve this? - Aram

1 Answers

1
votes

I don't know android, so I may be way off base, but their code shows:

mimeBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(fileDir + filename);

mimeBodyPart.setDataHandler(new DataHandler(source));
mimeBodyPart.setFileName(filename);
String contentType = Files.probeContentType(FileSystems.getDefault()
    .getPath(fileDir, filename));

You are encoding the base64 directly, which explodes into a fairly large string. The FileDataSource likely works around that.