ngImgCrop icon indicating copy to clipboard operation
ngImgCrop copied to clipboard

How can I save cropped image into server using node js

Open sreeharieengayil opened this issue 9 years ago • 2 comments

Hi,

May I know ,how to save cropped image to server using node js.I am new to this.

sreeharieengayil avatar Feb 16 '15 11:02 sreeharieengayil

Did you get an answer to this... I am looking for the same solution.

tomrainedotcom avatar Aug 26 '15 05:08 tomrainedotcom

Send the image (which is in form of a base64 encoded string) in POST request to your nodejs server. Write an API to consume that request on node side. For saving the code should look something like this.

var image = req.body.image.replace(/^data:image\/jpeg;base64,/, "");
var filePath = 'imagecontents/';
fileName = filePath +'abc.jpg';

mkdirp(path.join(__dirname, '../../..' + filePath), function (err) {
                     if (err) {
                         logger.log('error', err);
                         res.sendStatus(500);
                         throw err;
                     }

require("fs").writeFile(path.join(__dirname, '../../..' + fileName), image, 'base64', function (err) {
                         if (err) {
                             logger.log('error', err);
                             res.sendStatus(500);
                             throw err;
                         }
                     });

PS. If you intend to push images to s3, use aws-sdk.

ketansp avatar Jan 04 '16 17:01 ketansp