Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert base64 cryptobot image to blob #12

Open
bhaskarSingh opened this issue Mar 28, 2021 · 0 comments · Fixed by #13
Open

Convert base64 cryptobot image to blob #12

bhaskarSingh opened this issue Mar 28, 2021 · 0 comments · Fixed by #13
Assignees
Labels
enhancement New feature or request +P1 Priority 1 - Top priority - Fix ASAP

Comments

@bhaskarSingh
Copy link
Member

Currently, base64 type of crypto bot image is stored on IPFS. Need to convert it to blob type of jpge/png for easier access.

Here are a few helpful links and methods for resolving the issue.

  1. Link: https://stackoverflow.com/questions/21227078/convert-base64-to-image-in-javascript-jquery
function base64toBlob(base64Data, contentType) {
    contentType = contentType || '';
    var sliceSize = 1024;
    var byteCharacters = atob(base64Data);
    var bytesLength = byteCharacters.length;
    var slicesCount = Math.ceil(bytesLength / sliceSize);
    var byteArrays = new Array(slicesCount);

    for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
        var begin = sliceIndex * sliceSize;
        var end = Math.min(begin + sliceSize, bytesLength);

        var bytes = new Array(end - begin);
        for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
            bytes[i] = byteCharacters[offset].charCodeAt(0);
        }
        byteArrays[sliceIndex] = new Uint8Array(bytes);
    }
    return new Blob(byteArrays, { type: contentType });
}
  1. https://stackoverflow.com/questions/45817204/how-to-convert-base64-string-into-file-object-in-javascript-which-should-work-in

  2. https://stackoverflow.com/questions/35940290/how-to-convert-base64-string-to-javascript-file-object-like-as-from-file-input-f

@bhaskarSingh bhaskarSingh added +P1 Priority 1 - Top priority - Fix ASAP enhancement New feature or request labels Mar 28, 2021
@bhaskarSingh bhaskarSingh reopened this Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request +P1 Priority 1 - Top priority - Fix ASAP
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants