I use google php client library to talk with gmail api.
I am trying to report the file size of an attachment using this API.
To check this, I sent an email with the application. I knew that the size of this application is 511 KB. Gmail web ui reports this application as 499K, which I suppose is pretty close:

When I extract this image using the gmail json api , however, I get the correct attachment size:
GET https://www.googleapis.com/gmail/v1/users/me/messages/14ef5015d08312fd/attachments/ANGjdJ-Yy2H2avT5aFV7akMM2Lp4NigSpHqKgMT48zUMPVe3l6B9U0cfs-jXYD3cWJPhEwVjXQxNg2ZGDBFXKpMnf1HbpoBCwzcuOYSAJmHBbMHGANWKynofHf5GyStvjHhvNpA5xwla2hj7zdm6SVISoMgAR-dHJIPXbRniHVdryv13bxNsUeuRFvYbktnAcIwi-ppD6C1VAJtnGQYIKtNjsOa68hOlMSGLByWOrbB2txEN_P4cM43U7SEEzFmIDjFhKGkEIiU1rvrf9WT8KFVTsJ1U9_nTFjfkXIjl_Q?key={YOUR_API_KEY}
returns
{ "size": 510808, "data": "encoded_data_string_uiasd82187" }
So there is a slight disconnect between what the gmail gmail web user shows and what the actual size of the attachment is. But here, where it is strange:
When I make a request a whole message (and not just an attachment) aka, a request like this:
GET https://www.googleapis.com/gmail/v1/users/me/messages/14ef5015d08312fd?key={YOUR_API_KEY}
I get json response as follows:
"body": { "attachmentId": "ANGjdJ9P-2Q_1lMch1_smv_ZKACDE_QRtBisZ8bAWP1x_-ze8tvQiQunNCjcWUDkv2kjZo67AETe6Zmti5YZ3Zl4-EyaNtbtfxWOHBhTqQFSK673hZhEWW8Bg7Ul4ws2eOSYXrZsvWY8NhLptXJP5PM0W30LZk2sHj4XLWlmU64YxMPAOXwLOT1FeNc3EgVvlKJFQv1sUVajmA6c1K_qKgH_Y_c56fSJAz9aFRoh9RW6wvkhTV5NeLm9WFghkzpInwz6cm-DyJQhY-eOZLE2mvqQ4EmCPmBgzwNDh29mqQ", "size": 699004 } -ze8tvQiQunNCjcWUDkv2kjZo67AETe6Zmti5YZ3Zl4-EyaNtbtfxWOHBhTqQFSK673hZhEWW8Bg7Ul4ws2eOSYXrZsvWY8NhLptXJP5PM0W30LZk2sHj4XLWlmU64YxMPAOXwLOT1FeNc3EgVvlKJFQv1sUVajmA6c1K_qKgH_Y_c56fSJAz9aFRoh9RW6wvkhTV5NeLm9WFghkzpInwz6cm-DyJQhY-eOZLE2mvqQ4EmCPmBgzwNDh29mqQ", "body": { "attachmentId": "ANGjdJ9P-2Q_1lMch1_smv_ZKACDE_QRtBisZ8bAWP1x_-ze8tvQiQunNCjcWUDkv2kjZo67AETe6Zmti5YZ3Zl4-EyaNtbtfxWOHBhTqQFSK673hZhEWW8Bg7Ul4ws2eOSYXrZsvWY8NhLptXJP5PM0W30LZk2sHj4XLWlmU64YxMPAOXwLOT1FeNc3EgVvlKJFQv1sUVajmA6c1K_qKgH_Y_c56fSJAz9aFRoh9RW6wvkhTV5NeLm9WFghkzpInwz6cm-DyJQhY-eOZLE2mvqQ4EmCPmBgzwNDh29mqQ", "size": 699004 }
So the attachment with the ID I'm looking for seems to be 699 KB in size, and not 511 KB of true size. This is most likely the size of the encoded attachment, not the raw file.
So, using the PHP client library, when I have a Google_Service_Gmail_MessagePart representing this attachment and I call $messagepart->getBody()->getSize() , this returns 699004.
I need a true attachment size, 510808.
How can I get this true size, and is there a bug in the gmail API showing the wrong size in this context?