I have backenda back end using node.js and a frontendfront end using jquery, javascript, ajax, and bootstrap. I want to upload an Imageimage from frontendfront end and save it to the mongoose database.Here Here the file is loading successfully and image will be in the location called /public/img but. But how can I save those image information into the database using apian API call.My code
Below is in belowmy code:
/server.js/server.js
/api/requests.js/api/requests.js
/schema/Data.js/schema/Data.js
'use strict'; exports = module.exports = function(app, mongoose) { var dataSchema = new mongoose.Schema({ image_title : { type: String, unique: true, lowercase: true }, image_url : { type: String, unique: true, lowercase: true } }); app.db.model('Data', dataSchema); }; /models.js/models.js
/routes.js/routes.js
{ image_title: exampleImage, image_url: xyzscjnscncsl.exampleImage.png } /public/index.html/public/index.html
/public/javascript/image.js/public/javascript/image.js
/* How to save image data from here to the mongoose db using api called */an API call?
$(document).ready(function() { $('#uploadForm').submit(function() { $("#status").empty().text("File is uploading..."); $(this).ajaxSubmit({ error: function(xhr) { status('Error: ' + xhr.status); }, success: function(response) { console.log(response) $("#status").empty().text(response); } }); return false; }); });