-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #325 from AutomatingSciencePipeline/development
Change the storage bucket to mongodb, add default experiments to database, other changes
- Loading branch information
Showing
12 changed files
with
192 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import clientPromise, { DB_NAME, COLLECTION_RESULTS_CSVS, COLLECTION_EXPERIMENT_FILES } from '../../../lib/mongodb'; | ||
import { NextApiHandler } from 'next'; | ||
import { GridFSBucket } from 'mongodb'; | ||
import { Readable } from 'stream'; | ||
|
||
const mongoFileUploader: NextApiHandler<string> = async (req, res) => { | ||
if (req.method === 'POST') { | ||
const { fileToUpload, experimentId } = req.body; | ||
|
||
if (!fileToUpload || !experimentId) { | ||
return res.status(400).json({ response: "Not enough arguments!" } as any); | ||
} | ||
|
||
try { | ||
const client = await clientPromise; | ||
const db = client.db(DB_NAME); | ||
const bucket = new GridFSBucket(db, { bucketName: 'fileBucket' }); | ||
|
||
const readableStream = new Readable(); | ||
readableStream.push(fileToUpload); | ||
readableStream.push(null); | ||
|
||
readableStream. | ||
pipe(bucket.openUploadStream(`experimentFile${experimentId}`, { | ||
chunkSizeBytes: 1048576, | ||
metadata: { expId: experimentId } | ||
}) as any); | ||
|
||
|
||
res.status(200).json({ response: 'Successfully wrote file!' } as any); | ||
return; | ||
} | ||
catch (error) { | ||
const message = "Failed to upload experiment file!"; | ||
console.error("Error writing experiment file."); | ||
res.status(500).json({ response: message } as any); | ||
} | ||
} | ||
} | ||
|
||
export default mongoFileUploader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,4 +58,4 @@ spec: | |
secretKeyRef: | ||
name: secret-env | ||
key: MONGODB_PASSWORD | ||
|
||
|