0

I am working to implement FB register/login in Laravel & Vue.js. What I want is just to convert FB avatar to base64 string in Vue. I am using croppie package(https://github.com/Foliotek/Croppie), so I need to convert the remote image(Facebook avatar) to base64 string, so that I can show the avatar to the guests as well. Please help me.

Thanks in advance.

2
  • in what format does your code get the image now, prior to conversion? Commented Oct 7, 2019 at 1:09
  • Because I need to keep the current workflow. But now it's ok. thank you for your consideration. Commented Oct 7, 2019 at 2:01

1 Answer 1

1

I am sorry to take your time. I have solved it myself as well.


    imgTo64(url) {
        var vm = this
        var xhr = new XMLHttpRequest();
        xhr.onload = function () {
            var arr = new Uint8Array(this.response);
            var raw = String.fromCharCode.apply(null, arr);
            var b64 = btoa(raw);

            var dataURL = 'data:image/' + dataType + ';base64,' + b64;

            console.log(dataURL);
        };

        var dataType = 'jpeg';
        xhr.open('GET', url);
        xhr.responseType = 'arraybuffer';
        xhr.send();
    },

If anyone want to get same thing, hope to get solution from my code. Thank you!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.