mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-06 22:59:24 -06:00
fix: s3 file upload (#3050)
Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
This commit is contained in:
@@ -35,10 +35,13 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@formbricks/config-typescript": "workspace:*",
|
||||
"@formbricks/types": "workspace:*",
|
||||
"@formbricks/eslint-config": "workspace:*",
|
||||
"@formbricks/types": "workspace:*",
|
||||
"@rollup/plugin-inject": "^5.0.5",
|
||||
"buffer": "^6.0.3",
|
||||
"terser": "^5.31.6",
|
||||
"vite": "^5.4.1",
|
||||
"vite-plugin-dts": "^3.9.1"
|
||||
"vite-plugin-dts": "^3.9.1",
|
||||
"vite-plugin-node-polyfills": "^0.22.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/* eslint-disable no-console -- used for error logging */
|
||||
import { Buffer } from "node:buffer";
|
||||
import type { TUploadFileConfig, TUploadFileResponse } from "@formbricks/types/storage";
|
||||
|
||||
export class StorageAPI {
|
||||
@@ -63,11 +64,23 @@ export class StorageAPI {
|
||||
}
|
||||
|
||||
const formData: Record<string, string> = {};
|
||||
const formDataForS3 = new FormData();
|
||||
|
||||
if (presignedFields) {
|
||||
Object.keys(presignedFields).forEach((key) => {
|
||||
formData[key] = presignedFields[key];
|
||||
formDataForS3.append(key, presignedFields[key]);
|
||||
});
|
||||
|
||||
try {
|
||||
const buffer = Buffer.from(file.base64.split(",")[1], "base64");
|
||||
const blob = new Blob([buffer], { type: file.type });
|
||||
|
||||
formDataForS3.append("file", blob);
|
||||
} catch (buffErr) {
|
||||
console.error({ buffErr });
|
||||
|
||||
throw new Error("Error uploading file");
|
||||
}
|
||||
}
|
||||
|
||||
formData.fileBase64String = file.base64;
|
||||
@@ -86,7 +99,7 @@ export class StorageAPI {
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
body: JSON.stringify(formData),
|
||||
body: presignedFields ? formDataForS3 : JSON.stringify(formData),
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("Error uploading file", err);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { resolve } from "path";
|
||||
import { defineConfig } from "vite";
|
||||
import dts from "vite-plugin-dts";
|
||||
import { nodePolyfills } from "vite-plugin-node-polyfills";
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
@@ -16,5 +17,13 @@ export default defineConfig({
|
||||
fileName: "index",
|
||||
},
|
||||
},
|
||||
plugins: [dts({ rollupTypes: true })],
|
||||
plugins: [
|
||||
dts({ rollupTypes: true }),
|
||||
nodePolyfills({
|
||||
include: ["buffer"],
|
||||
globals: {
|
||||
Buffer: true,
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
@@ -232,6 +232,7 @@ export const getS3UploadSignedUrl = async (
|
||||
Key: `${environmentId}/${accessType}/${fileName}`,
|
||||
Fields: {
|
||||
"Content-Type": contentType,
|
||||
"Content-Encoding": "base64",
|
||||
},
|
||||
Conditions: postConditions,
|
||||
});
|
||||
|
||||
733
pnpm-lock.yaml
generated
733
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user