Wednesday, 10 May 2017

Encode and decode nodjs image using base64

What i am trying to approach is basicly this:

  1. in the client before send a image encode it and send as text to server
  2. Server receive in post method and save the decoded text
  3. When downloading i want to decode the text again and display the image

Forget about the client, i am just testing this using postman and nodeJS, so im just worried about the server side.

I use module abse64-image-upload, so at the moment i have this:

app.get('/upload', function (req, res) {
    console.log("HY");
    uploader.upload(image, { mime: "image/png", headers: { 'X-Access-Token': '123456789' } }, function (err, response) {
        if (!err && response.statusCode == 200) {
            console.log(JSON.parse(response.body));
            // handle response 
        } else {
            console.log(err, response);
            // handle errors 
        }
    });
})

i get a problem related to sockets:

 Error: socket hang up
    at TLSSocket.onHangUp (_tls_wrap.js:1124:19)
    at TLSSocket.g (events.js:292:16)
    at emitNone (events.js:91:20)
    at TLSSocket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9) code: 'ECONNRESET' } undefined

how can i receive the code on the post method in the upload method?



via Antonio Costa

No comments:

Post a Comment