Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Bug: netlify dev mangles base64 upload #143

Closed
sanderhahn opened this issue Apr 19, 2019 · 1 comment
Closed

Bug: netlify dev mangles base64 upload #143

sanderhahn opened this issue Apr 19, 2019 · 1 comment

Comments

@sanderhahn
Copy link
Contributor

sanderhahn commented Apr 19, 2019

- What is the current behavior?

Binary file upload base64 is mangled when uploaded to netlify dev. The same upload to a deployed site works correctly. The binary is a transparant png for demo purposes:

$ base64 pixel-transparent.png
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII=

The function just displays the base64 data that is made available:

exports.handler = async function (event, context) {
    return {
        statusCode: 200,
        body: JSON.stringify({
            base64: event.isBase64Encoded,
            data: event.body,
        }),
    };
};

- If the current behavior is a bug, please provide the steps to reproduce.

Upload to netlify dev site:

$ curl -X POST -H "Content-Type: image/jpeg" --data-binary "@pixel-transparent.png" http://localhost:8888/.netlify/functions/body
{"base64":true,"data":"77+9UE5HDQoaCgAAAA1JSERSAAAAAQAAAAEIBAAAAO+/vRwMAgAAAAtJREFUeO+/vWPvv73vv70AAAIHAQLvv70cMXEAAAAASUVORO+/vUJg77+9"}

- What is the expected behavior?

Upload to deployed site:

$ curl -X POST -H "Content-Type: image/jpeg" --data-binary "@pixel-transparent.png" https://{site_id}.netlify.com/.netlify/functions/body
{"base64":true,"data":"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5C"}

OS: mac
Node: v10.11.0

Thanks for making Netlify!
Works great :)

@sanderhahn sanderhahn changed the title Bug: netlify dev mangles base64 upload Bug: netlify dev mangles base64 upload Apr 19, 2019
@swyxio
Copy link
Contributor

swyxio commented Apr 19, 2019

this sounds very similar to a thing we had in netlify-lambda: https://github.com/netlify/netlify-lambda/pull/68/files

i'm not going to work on this right now but will welcome PRs if you can figure it out. its probably going to be pretty similar and we may have just missed a detail or two. equivalent code is around here:

lambdaResponse.isBase64Encoded

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants