Skip to content

Commit

Permalink
fix(framework): base64 encoded response were not being decoded
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclimse committed Jul 24, 2024
1 parent c745812 commit d2aab3e
Show file tree
Hide file tree
Showing 6 changed files with 4,031 additions and 2,430 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Initial project setup
- Local testing utils
- Repository setup

## v0.1.2

### Fixed

- Added support for `isBase64Encoded` in response
26 changes: 26 additions & 0 deletions examples/base64/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { pathToFileURL } from "url";

// Using the "isBase64Encoded" property in the response object, you can return a base64 encoded image
// The object will be automatically converted back to binary by the runtime.
async function handler(event, context, callback) {
const resp = await fetch("https://http.cat/images/200.jpg");

const buf = await resp.arrayBuffer();
const b64Cat = Buffer.from(buf).toString("base64");

return {
statusCode: 200,
body: b64Cat,
isBase64Encoded: true,
headers: {
"Content-Type": "image/jpeg",
},
};
}

// This will execute when testing locally, but not when the function is launched
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
import("@scaleway/serverless-functions").then(scw_fnc_node => {
scw_fnc_node.serveHandler(handler, 8080);
});
}
Loading

0 comments on commit d2aab3e

Please sign in to comment.