Skip to content

Node.js Upload multiple images to MongoDB example #371

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

Open
coding-to-music opened this issue Jan 24, 2022 · 0 comments
Open

Node.js Upload multiple images to MongoDB example #371

coding-to-music opened this issue Jan 24, 2022 · 0 comments

Comments

@coding-to-music
Copy link
Owner

Node.js Upload multiple images to MongoDB example

https://github.com/coding-to-music/node-js-upload-image-mongodb

For more detail, please visit:

How to upload/store images in MongoDB using Node.js & Express

https://github.com/bezkoder/node-js-upload-image-mongodb

Front-end Apps to work with this Node.js Server:

More Practice:

Node.js Express File Upload Rest API example (static folder)

Node.js Express File Upload with Google Cloud Storage example

Upload & resize multiple images in Node.js using Express, Multer, Sharp

Node.js, Express & MongoDb: Build a CRUD Rest Api example

Server side Pagination in Node.js with MongoDB and Mongoose

Node.js + MongoDB: User Authentication & Authorization with JWT

Associations:

MongoDB One-to-One relationship tutorial with Mongoose examples

MongoDB One-to-Many Relationship tutorial with Mongoose examples

MongoDB Many-to-Many Relationship with Mongoose examples

Integration (run back-end & front-end on same server/port)

Integrate React with Node.js Restful Services

Integrate Angular with Node.js Restful Services

Integrate Vue with Node.js Restful Services

Project setup

npm install

Run

node src/server.js

Output

Running at localhost:8080
Error: The database connection must be open to store files
    at GridFsStorage._handleFile (/mnt/ap/ap/node-js-upload-image-mongodb/node_modules/multer-gridfs-storage/lib/gridfs.js:175:12)
    at /mnt/ap/ap/node-js-upload-image-mongodb/node_modules/multer/lib/make-middleware.js:145:17
    at allowAll (/mnt/ap/ap/node-js-upload-image-mongodb/node_modules/multer/index.js:8:3)
    at wrappedFileFilter (/mnt/ap/ap/node-js-upload-image-mongodb/node_modules/multer/index.js:44:7)
    at Busboy.<anonymous> (/mnt/ap/ap/node-js-upload-image-mongodb/node_modules/multer/lib/make-middleware.js:115:7)
    at Busboy.emit (events.js:400:28)
    at Busboy.emit (/mnt/ap/ap/node-js-upload-image-mongodb/node_modules/busboy/lib/main.js:38:33)
    at PartStream.<anonymous> (/mnt/ap/ap/node-js-upload-image-mongodb/node_modules/busboy/lib/types/multipart.js:213:13)
    at PartStream.emit (events.js:400:28)
    at HeaderParser.<anonymous> (/mnt/ap/ap/node-js-upload-image-mongodb/node_modules/dicer/lib/Dicer.js:51:16) {
  storageErrors: []
}

{"message":"Error when trying upload many files: Error: The database connection must be open to store files"}

Attempt to connect to the database

localhost:8080/files

Output

{"message":"connect ECONNREFUSED 127.0.0.1:27017"}

Mongod port

localhost:27017

Output

It looks like you are trying to access MongoDB over HTTP on the native driver port.

Start the mongod database server

mongod

Go to route files

http://localhost:8080/files

Output

{"message":"No files found!"}


Upload a file

```java
http://localhost:8080/

Output

{"message":"Files have been uploaded."}

Upload a file

http://localhost:8080/files

Output

[{"name":"1640923740720-bezkoder-step5d.png","url":"http://localhost:8080/files/1640923740720-bezkoder-step5d.png"}]

Console Output

Running at localhost:8080
[
  {
    fieldname: 'file',
    originalname: 'step5d.png',
    encoding: '7bit',
    mimetype: 'image/png',
    id: new ObjectId("61ce825c48a0585965e88d45"),
    filename: '1640923740720-bezkoder-step5d.png',
    metadata: null,
    bucketName: 'photos',
    chunkSize: 261120,
    size: 118473,
    md5: undefined,
    uploadDate: 2021-12-31T04:09:00.799Z,
    contentType: 'image/png'
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant