diff --git a/packages/server/src/routes/attachments/index.ts b/packages/server/src/routes/attachments/index.ts index abe09a6c89c..a4223781f72 100644 --- a/packages/server/src/routes/attachments/index.ts +++ b/packages/server/src/routes/attachments/index.ts @@ -1,11 +1,11 @@ import express from 'express' import multer from 'multer' -import path from 'path' import attachmentsController from '../../controllers/attachments' +import { getUploadPath } from '../../utils' const router = express.Router() -const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` }) +const upload = multer({ dest: getUploadPath() }) // CREATE router.post('/:chatflowId/:chatId', upload.array('files'), attachmentsController.createAttachment) diff --git a/packages/server/src/routes/documentstore/index.ts b/packages/server/src/routes/documentstore/index.ts index 789a35662e9..e0892cfc404 100644 --- a/packages/server/src/routes/documentstore/index.ts +++ b/packages/server/src/routes/documentstore/index.ts @@ -1,10 +1,10 @@ import express from 'express' -import documentStoreController from '../../controllers/documentstore' import multer from 'multer' -import path from 'path' +import { getUploadPath } from '../../utils' +import documentStoreController from '../../controllers/documentstore' const router = express.Router() -const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` }) +const upload = multer({ dest: getUploadPath() }) router.post(['/upsert/', '/upsert/:id'], upload.array('files'), documentStoreController.upsertDocStoreMiddleware) diff --git a/packages/server/src/routes/openai-assistants-files/index.ts b/packages/server/src/routes/openai-assistants-files/index.ts index 771e5fd6d26..d717754715f 100644 --- a/packages/server/src/routes/openai-assistants-files/index.ts +++ b/packages/server/src/routes/openai-assistants-files/index.ts @@ -1,10 +1,10 @@ import express from 'express' import multer from 'multer' -import path from 'path' import openaiAssistantsController from '../../controllers/openai-assistants' +import { getUploadPath } from '../../utils' const router = express.Router() -const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` }) +const upload = multer({ dest: getUploadPath() }) router.post('/download/', openaiAssistantsController.getFileFromAssistant) router.post('/upload/', upload.array('files'), openaiAssistantsController.uploadAssistantFiles) diff --git a/packages/server/src/routes/openai-assistants-vector-store/index.ts b/packages/server/src/routes/openai-assistants-vector-store/index.ts index 1560e37ecf7..a6721566c12 100644 --- a/packages/server/src/routes/openai-assistants-vector-store/index.ts +++ b/packages/server/src/routes/openai-assistants-vector-store/index.ts @@ -1,10 +1,10 @@ import express from 'express' import multer from 'multer' -import path from 'path' import openaiAssistantsVectorStoreController from '../../controllers/openai-assistants-vector-store' +import { getUploadPath } from '../../utils' const router = express.Router() -const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` }) +const upload = multer({ dest: getUploadPath() }) // CREATE router.post('/', openaiAssistantsVectorStoreController.createAssistantVectorStore) diff --git a/packages/server/src/routes/predictions/index.ts b/packages/server/src/routes/predictions/index.ts index ded2d34248d..ca192c89fb2 100644 --- a/packages/server/src/routes/predictions/index.ts +++ b/packages/server/src/routes/predictions/index.ts @@ -1,11 +1,11 @@ import express from 'express' import multer from 'multer' -import path from 'path' import predictionsController from '../../controllers/predictions' +import { getUploadPath } from '../../utils' const router = express.Router() -const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` }) +const upload = multer({ dest: getUploadPath() }) // CREATE router.post(['/', '/:id'], upload.array('files'), predictionsController.getRateLimiterMiddleware, predictionsController.createPrediction) diff --git a/packages/server/src/routes/vectors/index.ts b/packages/server/src/routes/vectors/index.ts index cc257bcab8b..060d7e4b34e 100644 --- a/packages/server/src/routes/vectors/index.ts +++ b/packages/server/src/routes/vectors/index.ts @@ -1,11 +1,11 @@ import express from 'express' import multer from 'multer' -import path from 'path' import vectorsController from '../../controllers/vectors' +import { getUploadPath } from '../../utils' const router = express.Router() -const upload = multer({ dest: `${path.join(__dirname, '..', '..', '..', 'uploads')}/` }) +const upload = multer({ dest: getUploadPath() }) // CREATE router.post( diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index d8d233dd297..0946885b3a4 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -1680,3 +1680,9 @@ export const getAPIOverrideConfig = (chatflow: IChatFlow) => { return { nodeOverrides: {}, variableOverrides: [], apiOverrideStatus: false } } } + +export const getUploadPath = (): string => { + return process.env.BLOB_STORAGE_PATH + ? path.join(process.env.BLOB_STORAGE_PATH, 'uploads') + : path.join(getUserHome(), '.flowise', 'uploads') +}