Skip to content

Example uploading images to a static directory and making an entry into a MongoDB database. Example code for CSCI 277: Application Development I, Drury University. This code was assembled from various online examples.

Notifications You must be signed in to change notification settings

ssigman/MongoDB-Image-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB-Image-Example

Example uploading images to a static directory and making an entry into a MongoDB database. Example code for CSCI 277: Application Development I, Drury University. This code was assembled from various online examples.

Directions

  1. Clone the repo to your local machine.
  2. In the working directory of your local repo install the node project with the command: npm install
  3. If the MongoDB service is not started, start it with the command:
mongod -dbpath <<absolute path to your data directory>>
  1. Using the MongoDB command line tool (mongo), create the database imageDB and add the image public/images/SSDLC_Pedal_View.png to a collection called images. The following command sequence can be used:
  • mongo
  • use imageDB
  • create the following document:
image = {
  "filename" : "SSDLC_Pedal_View.png", 
  "photo_name" : "Security Touchpoints in Pedal",
  "album" : "tech drawings", 
  "upload_date" : ISODate()
}
  • exit
  1. Open a terminal (command shell) and change directory to the working directory of your project.
  2. Start the web server with either the command npm start or node start.
  3. To run the app
  1. (Current Version) Pointing your browser to http://localhost:3000/getImages will return a JSON array of images you have saved in the database.

Note 1: You may check the images whether your images have uploaded at any time using the MongoDB command line tool, mongo. The command to use is db.images.find().

Note 2: The next version of this example will illustrate using an AJAX call to process the array of image information returned by the /getImages route.

About

Example uploading images to a static directory and making an entry into a MongoDB database. Example code for CSCI 277: Application Development I, Drury University. This code was assembled from various online examples.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published