1
votes

I am using the Gmail API to import messages, and I have noticed the following issue. Currently I am doing a POST to this url:

https://www.googleapis.com/gmail/v1/users/me/messages?uploadType=multipart

The following http headers are set:

Content-Length: <n>
Content-Type: application/json

The posted json data looks like this:

{
"labelIds": ["Label_154"],
"raw": "RnJvbTo..."
}

(the raw data of course is a much larger based64 encoded RFC-822 message)

This works but for one customer they are getting http 413 errors on some messages, which I believe means that the message is too large. I have not yet found out how big the actual message is. I have seen some documentation that says I should use this url instead:

https://www.googleapis.com/upload/gmail/v1/users/me/messages?uploadType=multipart

But then the API complains that json is not supported, I should use Content-Type message/rfc822. I was hoping to continue to use json and raw encoded data so I don't have to make substantial changes to my code. Can you tell me what the actual message size limit is for this method, and is there a way I can go up to the full 35mb limit using a different endpoint?

1

1 Answers

1
votes

For anything larger than a few MB it's best to use the media (/upload) path. Yes, that only accepts email messages (message/rfc822 payload). Hopefully shouldn't be too difficult to change code. Since you already have to have a base64(message/rfc822) to send to the existing JSON endpoint, you can just stop doing the base64 of the message and then wrapping it in JSON.

If you use the /upload endpoint you'll be able to send messages all the way up to the max gmail message size (25MB, which after base64 encoding may be as much as 34MB).