We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

squidlauncher64's avatar
squidlauncher64
Explorer | Level 3
2 years ago

downloading an image using dropbox API

Hello,   I am trying to download an image from dropbox api in react native. I am getting a success code: '200' and the response says that it is ok. I have included some of the javascript code below...
  • Здравко's avatar
    Здравко
    2 years ago

    Hi squidlauncher64,

    You didn't account that 'blob' method doesn't return actual blob, but Promise object wrapping this blob! That's where all your troubles come from. Also when you try to stringify some object, you're getting object declaration (no actual data) and that's why appear so short result - "[object Object]" - i.e. one more mess. 🙂

    You have to handle correct type in correct way. A simplistic example follows:

    var reader = new FileReader();
    await fetch(...all staff here...).then((r)=>r.blob()).then((b)=>reader.readAsDataURL(b));
    var b64encoded = reader.result;
    var rawBase64 = b64encoded.slice(b64encoded.search(',')+1);

    Depending on what you need either full encoded result (b64encoded) can be used or only the actual/raw base64 encoded string part (rawBase64). 😉

    Hope this helps.