I am new to programming and I am trying to store images which i recieve as POST request from my Client to my server
- Client::
Android
- Server::
ExpressJS running on AWS
- Database i am using ::
MySQL
In MySQL DATABASE
- I have created a Database in mySQL::
restaurants
- There is a table named::
ReataurantGalleryImages
I am using relative path to store the images
I have to store the images in the place as below which is a public directory to store images in express
/public/images
My Express Code that i have tried::
var express = require('express')
, async = require('async')
, http = require('http')
, mysql = require('mysql');
var app = express();
var connection = mysql.createConnection({
host: 'localhost',
user: '******',
password: "******",
database: '**********'
});
connection.connect();
// all environments
app.set('port', process.env.PORT || 1234);
app.use(express.static(__dirname + '/public/images'));
app.post('/Name/',function(request,response,next){
app.use(express.bodyParser());
var keyName = new Buffer(request.query.Key, 'base64').toString('binary');
var keyImage = new Buffer(request.query.Key2, 'base64').toString('binary');
var name_of_restaurants;
async.series( [
function(callback) {
connection.query('INSERT INTO RestaurantGalleryImages (Images,RestName) VALUES (?,?)', [keyImage,keyName], function (err, rows, fields)
{
console.log('Connection result error ' + err);
callback();
});
}
// Send the response
] );
} );
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
My Queries::
- Am i correct with my code
- How it the name gets stored in table for the varchar field (
Images
) and file for the location/MyDirectory/projects/MyProject/public/images
- How mapping of whole thing takes place
Hope i am clear . Thanks