Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lambda) File uploads #4506

Merged
14 changes: 6 additions & 8 deletions packages/apollo-server-lambda/src/lambdaApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ export function graphqlLambda(
callback,
): void => {
context.callbackWaitsForEmptyEventLoop = false;
let { body, isBase64Encoded } = event;
let { body, headers, isBase64Encoded } = event;
let query: Record<string, any> | Record<string, any>[];
const contentType = headers["content-type"] || headers["Content-Type"];
const isMultipart = (contentType || "").startsWith("multipart/form-data");
mathix420 marked this conversation as resolved.
Show resolved Hide resolved

if (body && isBase64Encoded) {
if (body && isBase64Encoded && !isMultipart) {
body = Buffer.from(body, 'base64').toString();
}

Expand All @@ -45,12 +48,7 @@ export function graphqlLambda(
});
}

const contentType = event.headers["content-type"] || event.headers["Content-Type"];
let query: Record<string, any> | Record<string, any>[];

if (body && event.httpMethod === 'POST' &&
contentType && contentType.startsWith("multipart/form-data")
) {
if (body && event.httpMethod === 'POST' && isMultipart) {
query = body as any;
} else if (body && event.httpMethod === 'POST') {
query = JSON.parse(body);
Expand Down