0

I have used axios to get an image from database

          axios.get(`/file/${eventID}/logo1/${name}`,{

                headers:{

                    'Authorization' : `${token}`,
                    'content-type': 'image/png',
                    'accept': 'image/png'
                }
                
            }).then((res) => {

                console.log(res.data)
                this.logo1 = res.data

            }).catch((error) => {

                console.log(error)
            })

I am getting the res.data in the following format

enter image description here

I would like to display it in one of my pages.

  <b-row>
        <b-col>
            <div>
                <b-img :src="logo1" fluid alt=" "></b-img>
            </div>
        </b-col>
    </b-row>

How shall i implement it?

2 Answers 2

1

You can attach data:image/png;base64, to the base64 encoded logo1.

this.logo1 = 'data:image/png;base64,'+ btoa(res.data)
Sign up to request clarification or add additional context in comments.

4 Comments

I would suggest Base64 library (webtoolkit.info), because I've seen somewhere that btoa() has some flaws.
Hi, ok so i have to convert it to a base64 encoded image and then assign it to this.logo1 @JanMadeyski
can you let me know the result after you set the logo1 to the base64 code?
and you can use btoa() method - developer.mozilla.org/en-US/docs/Web/API/…
0

i made a small change. Added the response type as blob and then converted it into a URL. Now the image is displayed in fronted.

axios.get(`/file/${eventID}/logo1/${name}`,{

            headers:{

                'Authorization' : `${token}`,
                'content-type': 'image/png',
                'accept': 'image/png'
            },
            
            responseType: 'blob'
            
        }).then((res) => {

            const urlCreator = window.URL || window.webkitURL
            this.logo1 = urlCreator.createObjectURL(res.data)

        }).catch((error) => {

            console.log(error)
        })

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.