Skip to content

MongoDB file upload using NodeJS and Mongo GridFS

Notifications You must be signed in to change notification settings

houssem-yahiaoui/fileupload-nodejs

Repository files navigation

MongoDB/GridFS File upload with NodeJS.

Open Source Love Open Source Love code style: prettier

PS: This project have a JS/Es* Version and Typescript version that i will ry to keep in sync in term of integration, so for sake of clarity the DEV(this branch) will have the JS/ES* Version and ts-build Branch will have the Typescript Version.

As mouthfull as it sounds, but functional it will be, file upload is needed in any application there for this demo shows how we can upload files directly to our MongoDB using it's GridFS System.

NOTICE:

This project will be improved in near future to use the new supported version of file management in MongoDB, which is the GridFSBucket, this final support will be ported soon.

Dependencies Management :

In order to use this repository, please feel free to clone directly to your working directory and simply enter this command to your Terminal/CMD :

# yarn install

or, in case your don't dispose yarn, please use the following command:

# npm install

Launching the app :

In case you want to run the app, simply use the following command :

# npm start

Updates:

File Upload :

I've changed the upload endpoints so no in order to upload your documents you will just call for the endpoint bellow :

<localhost|server>/v1/bucket/upload

Checking Uplaoded files :

As an added endpoint, now you can view all your uploaded files using this endpoint:

<localhost|server>/v1/home

This endpoint will give you all uploaded docs within you Database in an array of object that will have the following:

    [{
        file_name: <uploaded-file-name>,
        file_id: <uploaded-file-id>,
        file_link: <auto-generated-downnload-link>
    }]
  1. file_name : The uploaded file name.
  2. file_id : An auto generated _if upon file upload over GridFS.
  3. file_link : An auto generated download link of your file for easy download.

File Download :

I've changed the download endpoints so no in order to download your documents you will just call for the endpoint bellow :

<localhost|server>/v1/bucket/download?document_id=<doc-id>

Change Log :

1 - Depedencies upgrade. 2 - Logger updates to match winston v3.3

Finally, for even more details please check this Youtube tutorial I've created that explains just that.

Link : https://youtu.be/pXHOF4GWuZQ

Collaborators :

  • Houssem Yahiaoui (@houssem-yahiaoui).

Happy Coding =D

About

MongoDB file upload using NodeJS and Mongo GridFS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •