0

I'm using nodejs for getting base64 file but i`m do it in wrong way and i suddenly encoded base64 from utf8 charset. I want to recover my files that stored in db, I tested lot of ways to get back my data but the result is nothing.

My problem for uploading images solved in this question:

Converted base64 image does not work, how can I get true base64 image?

The sample stored image in my db is like this (Its png image with real size: 23275 bytes):

https://files.fm/u/vt5f5chn

please help me to recover my files with any tools or programming languages.

Edit1:

I used this code to store data in mongo:

In my server file (pure nodejs):

    // Get the payload,if any
    const decoder = new StringDecoder('utf-8');
    let payload = '';
    req.on('data', (data) => {
        payload += decoder.write(data);
    });
    req.on('end', () => {
        payload += decoder.end();
        req.data = {
            payload
        });
        // ... other codes

In my api that stored data in mongo:

const newAttachment = new TicketAttachment({
    name:fileName,
    type:fileType,
    size:req.data.payload.length,
    content:req.data.payload
});

newAttachment.save();

And image of data stored in my mongo is:

https://files.fm/u/vq9747zv

Mehdi Yeganeh
  • 2,019
  • 2
  • 24
  • 42
  • the base-64 decode works; however, the header is wrong - instead of 137 80 78 71 13 10 26 10, it starts 239 191 189 80 78 71 13 10 - the first 3 bytes are borked; trying to see why, but: what did you do to encode it? it is entirely possible that you have irreparably corrupted the data. – Marc Gravell Nov 10 '18 at 19:19
  • @MarcGravell Thanks for helping me, its really big problem for me. I wrote Edit 1 to show my codes. please check it – Mehdi Yeganeh Nov 10 '18 at 19:49
  • @MarcGravell You are right about wrong bytes, i compared with true png image and i saw it. – Mehdi Yeganeh Nov 10 '18 at 19:53
  • It looks like you used an encoding backwards (so: tried to decode arbitrary bytes into a string). If you did that: the result is gibberish. Sorry, but: as I say - this could be toast. – Marc Gravell Nov 10 '18 at 20:34
  • 1
    239 191 189 (EF BF BD) is U+FFFD aka the replacement character, which means that in the source there was unencodable character. – ckuri Nov 10 '18 at 23:15
  • @ckuri, Is it means that i cannot recover my data? – Mehdi Yeganeh Nov 11 '18 at 08:31
  • Unfortunatelately this seems to be the case as it’s impossible to know which character was there originally. – ckuri Nov 11 '18 at 08:39

0 Answers0