Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@

const request = require('supertest');

// Quick test for base64 encoding
function isBase64(str) {
if (str.length % 4 != 0) return false;
var last2 = str.slice(-2);
const regex = /[A-Za-z0-9+\/=]{2}/gm;
var m = regex.exec(last2);
if (m) return true;

return false;
}

/*
OpenWhisk web action redirecting requests to Express

Expand Down Expand Up @@ -43,7 +54,10 @@ module.exports = exports = (app) => (args) => {
req.query(args.__ow_query);

if (args.__ow_body && (args.__ow_method === 'post' || args.__ow_method === 'put' || args.__ow_method === 'patch')) {
req = req.send(args.__ow_body);
var body = args.__ow_body
if (isBase64(body))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, this worked for content type application/json and with binary data in multipart/form-data

body = Buffer.from(body, "base64")
req = req.send(body);
}

app.action_params = args;
Expand Down