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

Non-globus upload file #135

Draft
wants to merge 1 commit into
base: v2
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/server/FolderRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
GlobusFolder
} from "../utils/types";

import { authMiddleWare, requestErrors, validator, schemas, prepareDataForDB, globusTaskList } from "./ServerUtil";

Check failure on line 19 in src/server/FolderRoutes.ts

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups
import Busboy from 'busboy';

Check failure on line 20 in src/server/FolderRoutes.ts

View workflow job for this annotation

GitHub Actions / lint

`busboy` import should occur before import of `express`

Check failure on line 20 in src/server/FolderRoutes.ts

View workflow job for this annotation

GitHub Actions / lint

'Busboy' is defined but never used

Check failure on line 20 in src/server/FolderRoutes.ts

View workflow job for this annotation

GitHub Actions / lint

'Busboy' is defined but never used

Check failure on line 20 in src/server/FolderRoutes.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
import type { BusboyConfig } from 'busboy';

Check failure on line 21 in src/server/FolderRoutes.ts

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups

Check failure on line 21 in src/server/FolderRoutes.ts

View workflow job for this annotation

GitHub Actions / lint

`busboy` type import should occur before import of `express`

Check failure on line 21 in src/server/FolderRoutes.ts

View workflow job for this annotation

GitHub Actions / lint

'BusboyConfig' is defined but never used

Check failure on line 21 in src/server/FolderRoutes.ts

View workflow job for this annotation

GitHub Actions / lint

'BusboyConfig' is defined but never used

Check failure on line 21 in src/server/FolderRoutes.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
import * as fs from "fs";
import * as os from "os";

const folderRouter = express.Router();

Expand Down Expand Up @@ -344,4 +348,48 @@
}
);

export default folderRouter;
// const storage = multer.memoryStorage();
// const upload = multer({ storage: storage }).single("file");
const busboy = require('busboy');

folderRouter.post(
"/:folderId/uploadFile",
async function (req, res) {
const bb = busboy({ headers: req.headers });
const uploadPath = path.join(__dirname, 'uploads');
console.log(`Upload path: ${uploadPath}`);

if (!fs.existsSync(uploadPath)) {
fs.mkdirSync(uploadPath);
}

bb.on('file', (fieldname: string, file: NodeJS.ReadableStream, filename: string, encoding: string, mimetype: string) => {
console.log(`Received file: ${filename}`);
const saveTo = path.join(uploadPath, filename);
file.pipe(fs.createWriteStream(saveTo));
});

bb.on('finish', () => {
res.writeHead(200, { 'Connection': 'close' });
res.end("File upload complete");
});

bb.on('error', (err: any) => {
console.error('Busboy error:', err);
res.status(500).send({ error: 'File upload failed' });
});

req.pipe(bb);

req.on('aborted', () => {
bb.destroy();
});

req.on('error', (err) => {
console.error('Request stream error:', err);
res.status(500).send({ error: 'Request stream failed' });
});
}
);

export default folderRouter;
Loading