Fix upload metadata missing when behind nginx

This commit is contained in:
Zaid Abdulla committed 2021-08-11 13:08:27 -07:00
1 parent 088e25cbb0
commit 359eca7bbc
2 files changed
+17 -11

No files matched your search

+4 -4
View File
@@ -509,11 +509,11 @@ router.put("/files/:id", async (ctx) => {
} }
const metadata = { const metadata = {
fileType: singleParam(ctx.request.headers["metadata.filetype"]) || "", fileType: singleParam(ctx.request.headers["metadata-filetype"]) || "",
oui: singleParam(ctx.request.headers["metadata.oui"]) || "", oui: singleParam(ctx.request.headers["metadata-oui"]) || "",
productClass: productClass:
singleParam(ctx.request.headers["metadata.productclass"]) || "", singleParam(ctx.request.headers["metadata-productclass"]) || "",
version: singleParam(ctx.request.headers["metadata.version"]) || "", version: singleParam(ctx.request.headers["metadata-version"]) || "",
}; };
const validate = authorizer.getValidator(resource, metadata); const validate = authorizer.getValidator(resource, metadata);
+13 -7
View File
@@ -204,14 +204,20 @@ export const component: ClosureComponent = (): Component => {
putFormComponent, putFormComponent,
Object.assign( Object.assign(
{ {
actionHandler: async (action, _object) => { actionHandler: async (action, obj) => {
if (action !== "save") if (action !== "save")
throw new Error("Undefined action"); throw new Error("Undefined action");
const object = Object.assign({}, _object); const file = obj["file"] ? obj["file"][0] : null;
const file = object["file"]
? object["file"][0] // nginx strips out headers with dot, so replace with dash
: null; const headers = {
delete object["file"]; "metadata-fileType": obj["metadata.fileType"] || "",
"metadata-oui": obj["metadata.oui"] || "",
"metadata-productclass":
obj["metadata.productClass"] || "",
"metadata-version": obj["metadata.version"] || "",
};
if (!file) { if (!file) {
notifications.push("error", "File not selected"); notifications.push("error", "File not selected");
return; return;
@@ -232,7 +238,7 @@ export const component: ClosureComponent = (): Component => {
try { try {
await upload( await upload(
file, file,
object, headers,
abortController.signal, abortController.signal,
progressListener progressListener
); );