Site: https://gallant-stonebraker-875750.netlify.app/
I am completely baffled on why a Binary PUT
is working fine locally, but is not working once deployed. I am trying to take a PUT
to my lambda and turn around and upload it to Amazon S3. In both local and production, the file gets to S3. However, the format is invalid. When posting the file to Amazon S3, I am using this as my PUT
:
data: parseBody( event.body, event.isBase64Encoded )
Where the parseBody()
method is as such:
function parseBody( body, isBase64Encoded ) {
if ( body instanceof Buffer ) {
return( body );
}
if ( isBase64Encoded ) {
return( Buffer.from( body, "base64" ) );
}
return( Buffer.from( body ) );
}
Locally, using netlify-lambda serve
, this works just fine. I can see that event.body
is of type Buffer in the local environment. However, once it goes to production, I can see that it is a String, that is not base64-encoded. As such, it is using that Buffer.from(body)
line.
When I do this locally, the file that lands on S3 is 81-bytes. When I do it in production, the same file lands on S3 is 113-bytes (and is corrupted).
When I try to print the Binary that is being PUT
to S3, locally it is:
'ļæ½PNG\r' +
'\n\u001a\n\u0000\u0000\u0000\r' +
'IHDR\u0000\u0000\u0000\n\u0000\u0000\u0000\n' +
'\b\u0006\u0000\u0000\u0000ļæ½2Ļ½\u0000\u0000\u0000\u0018IDAT(Scļæ½ļæ½ļæ½ļæ½\bļæ½8ļæ½\u0010_(Q?x\u0000eļæ½\u0013ļæ½ļæ½U\u0006ļæ½\u0000\u0000\u0000\u0000IENDļæ½B`ļæ½'
And, in production, it is:
'ļæ½PNG\r' +
'\n\u001a\n\u0000\u0000\u0000\r' +
'IHDR\u0000\u0000\u0000\n\u0000\u0000\u0000\n' +
'\b\u0006\u0000\u0000\u0000ļæ½2Ļ½\u0000\u0000\u0000\u0018IDAT(Scļæ½ļæ½ļæ½ļæ½ļæ½ļæ½\bļæ½8ļæ½\u0010_(Q?x\u0000eļæ½\u0013ļæ½ļæ½U\u0006ļæ½\u0000\u0000\u0000\u0000IENDļæ½B`ļæ½'
As you can see , these stringified binaries are almost the same, but not quite (Scļæ½ļæ½ļæ½ļæ½
vs Scļæ½ļæ½ļæ½ļæ½ļæ½ļæ½
).
I cannot figure out what is going wrong. Iāve been at this for 2-days, pouring through Google, pouring through the Support Forums ā nothing makes sense.