Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/api/image', function(req, res, next){
- const contract_address = req.body.contract_address;
- const artist_name = req.body.artist_name;
- const artist_address = req.body.artist_address;
- const name = req.body.name;
- const description = req.body.description;
- const price = req.body.price;
- const supply = req.body.supply;
- const nb_rows = req.body.nb_rows;
- const nb_cols = req.body.nb_cols;
- const original_width = req.body.original_width;
- const tile_height = req.body.tile_height;
- const tile_width = req.body.tile_width;
- const matches = req.body.uploadedImage.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/),
- response = {};
- if (matches.length !== 3) {
- return new Error('Invalid input string');
- }
- response.type = matches[1];
- response.data = new Buffer(matches[2], 'base64');
- const imageBuffer = response.data;
- const id = '_' + Math.random().toString(36).substr(2, 9);
- const fileName = id + '.jpg';
- try {
- console.log('tente linput')
- fs.writeFileSync("./images/" + fileName, imageBuffer, 'utf8');
- const queryString = " INSERT INTO images(id, contract_address, artiste_name, artiste_address, name,description, price, supply, nb_rows, nb_cols, original_width,original_height, tile_height, tile_width) VALUES (1, '23443','azer', '2344', 'tyu', 'ghtgr', 23, 2, 12, 1, 2, 2, 3)"
- //const queryString = "INSERT INTO images(id, contract_address, artiste_name, artiste_address, name,description, price, supply, nb_rows, nb_cols, original_width,original_height, tile_height, tile_width) VALUES (?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
- //connection.query(queryString, [3, contract_address, artist_name, artist_address, name, description, price, supply, nb_rows, nb_cols, original_width,3, tile_height, tile_width], (err, results, fields) => {
- connection.query(queryString,(err, results, fields) => {
- if(err){
- console.log("Failed to insert new user.");
- res.sendStatus(5400);
- return;
- }
- console.log('Inserted a new user with id : ', results.insertId);
- res.end();
- });
- } catch (e) {
- next(e);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement