Skip to content

Commit

Permalink
fix(framework): base64 encoded response were not being decoded (#137)
Browse files Browse the repository at this point in the history
## Summary

**_What's changed?_**

- Added support for the `isBase64EncodedResponse` property
- Added example to showcase change
- Bumped version to 1.1.2 to prepare release

**_Why do we need this?_**

- We should support base64 encoded response

**_How have you tested it?_**

- Added a simple unit test ✅ 
- Example is returning a cat picture ✅ 

## Checklist

- [x] I have reviewed this myself
- [x] There is a unit test covering every change in this PR
- [x] I have updated the relevant documentation

## Details
  • Loading branch information
cyclimse authored Jul 24, 2024
1 parent b8fe818 commit 1186a09
Show file tree
Hide file tree
Showing 7 changed files with 4,036 additions and 2,432 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
<!-- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -->

## v1.1.2

### Fixed

- Added support for `isBase64Encoded` in response

## v0.1.0

### Added
Expand Down
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 1186a09

Please sign in to comment.