Migrate Base64 and Timestamp handling from 1.x to 2.x
masterIn AWS SDK for JavaScript v2.x, the SDK automatically encodes and decodes Base64 and timestamp values. You no longer need to manually perform Base64 conversions for services like AWS.DynamoDB or AWS.SQS.
- Input: Pass the raw string or Buffer instead of a Base64 encoded string.
- Output: Base64 encoded values are returned as
Bufferobjects from server responses.
// 1.x approach (Manual Base64)
var params = {
MessageBody: 'Some Message',
MessageAttributes: {
attrName: {
DataType: 'Binary',
BinaryValue: new Buffer('example text').toString('base64')
}
}
};
// 2.x approach (Automatic)
var params = {
MessageBody: 'Some Message',
MessageAttributes: {
attrName: {
DataType: 'Binary',
BinaryValue: 'example text'
}
}
};
// Reading the response in 2.x
sqs.receiveMessage(params, function(err, data) {
// buf is <Buffer 65 78 61 6d 70 6c 65 20 74 65 78 74>
var buf = data.Messages[0].MessageAttributes.attrName.BinaryValue;
console.log(buf.toString()); // "example text"
});