1

I implemented push notification message for one of my application. I am getting notification in general but when i want to send actual data that is below 2k byte but getting below response with error...

request:

curl --header "Authorization: key=AIzaSyDx43ertyuOm459WczpBwAqKSw8IxFHGQs" --header Content-Type:"application/json" --header "Encryption: salt=wtKCDREj4rt562LWk1muo3FA==" --header "Crypto-Key: dh=BPqg7luAvMisfd45sj5ZaBX7GSz9sSfSt3lhpA3Ea3qHCE_l6pi4bXZ3AsNX179iGWMDDQT9IqhHyXBw0230_kc="  --header "Content-Encoding: aes56ggcm" https://android.googleapis.com/gcm/send -d "@/tmp/data" --insecure

/tmp/data having very less data.

Response:

{"multicast_id":6999436345666218533,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MessageTooBig"}]}

I looked at some articles and found below...

Check that the total size of the payload data included in a message does not exceed GCM limits: 4096 bytes for most messages, or 2048 bytes in the case of messages to topics or notification messages on iOS. This includes both the keys and the values.

but my complete payload data size is less that 2k bytes.

Any help would be appreciated.

Bimlesh Sharma
  • 186
  • 4
  • 18

2 Answers2

2

Message Too Big

The total size of the payload data that is included in a message can't exceed 4096 bytes. Note that this includes both the size of the keys as well as the values. Happens when error code is MessageTooBig.

According to Raghav Sood:

You can use the following to get the bytes of a String:

String s = "some text here";
byte[] b = s.getBytes("UTF-8");
int bytes = b.length;
Make sure that you specify the encoding of the String, as different encodings may take up a different number of bytes for the same String. In the above example, UTF-8 is used as the encoding.

To convert the bytes into kB, just divide by 1024.

This will help you ensure that your message is and will not exceed against the total size of payload data.

Community
  • 1
  • 1
Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91
1

I was having a similar problem "MessageTooBig" when it obviously wasn't while sending WebPush notifications via GCM.

It turned out that the problem was in Base64 encoding. As per web push encryption spec, for salt and public key url safe base64 encoding needs to be used, but for GCM raw_data you need to just "regular" Base64 encoding (with == at the end).

Changing base64 encoding for raw_data fixed this problem for me.