Browse Source

fix(nocodb): use local storage adapter for local attachments

pull/4931/head
Wing-Kam Wong 2 years ago
parent
commit
3fe516b4c9
  1. 9
      packages/nocodb/src/lib/meta/api/attachmentApis.ts

9
packages/nocodb/src/lib/meta/api/attachmentApis.ts

@ -12,6 +12,7 @@ import { Tele } from 'nc-help';
import extractProjectIdAndAuthenticate from '../helpers/extractProjectIdAndAuthenticate'; import extractProjectIdAndAuthenticate from '../helpers/extractProjectIdAndAuthenticate';
import catchError, { NcError } from '../helpers/catchError'; import catchError, { NcError } from '../helpers/catchError';
import NcPluginMgrv2 from '../helpers/NcPluginMgrv2'; import NcPluginMgrv2 from '../helpers/NcPluginMgrv2';
import Local from '../../v1-legacy/plugins/adapters/storage/Local';
import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants'; import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants';
const isUploadAllowed = async (req: Request, _res: Response, next: any) => { const isUploadAllowed = async (req: Request, _res: Response, next: any) => {
@ -121,12 +122,12 @@ export async function uploadViaURL(req: Request, res: Response) {
export async function fileRead(req, res) { export async function fileRead(req, res) {
try { try {
const storageAdapter = await NcPluginMgrv2.storageAdapter(); // get the local storage adapter to display local attachments
// const type = mimetypes[path.extname(req.s.fileName).slice(1)] || 'text/plain'; const storageAdapter = new Local();
const type = const type =
mimetypes[path.extname(req.params?.[0]).split('/').pop().slice(1)] || mimetypes[path.extname(req.params?.[0]).split('/').pop().slice(1)] ||
'text/plain'; 'text/plain';
// const img = await this.storageAdapter.fileRead(slash(path.join('nc', req.params.projectId, req.params.dbAlias, 'uploads', req.params.fileName)));
const img = await storageAdapter.fileRead( const img = await storageAdapter.fileRead(
slash( slash(
path.join( path.join(
@ -194,6 +195,7 @@ router.post(
catchError(upload), catchError(upload),
] ]
); );
router.post( router.post(
'/api/v1/db/storage/upload-by-url', '/api/v1/db/storage/upload-by-url',
@ -203,6 +205,7 @@ router.post(
catchError(uploadViaURL), catchError(uploadViaURL),
] ]
); );
router.get(/^\/download\/(.+)$/, catchError(fileRead)); router.get(/^\/download\/(.+)$/, catchError(fileRead));
export default router; export default router;

Loading…
Cancel
Save