2

How can i display my image which the image call from database but only return alot question mark... see here >>> Resdata

If i direct call the API using the link it come out it result:

{"success":false,"message":"No token provided"}
async getImage(){
const res = await MemberService.getmemberprofileimage('1667546872110-agape-1667546868823.jpeg').then(function(response){
        return response;
      })
      if(res.status == 200){
        if(res.data.success != false){
          this.gImage = res.data;
          console.log('Res:', res);
        }
      }
    }

ReturnData:

ReturnData

5
  • your response seems to be binary data. One way could be converting that to base64 data and pass it to an img element's src Commented Nov 7, 2022 at 9:55
  • Does this answer your question? Convert binary data to base64 with javascript Commented Nov 7, 2022 at 9:56
  • @GrafiCode the code change to base64 but I cant show on <img> tag Commented Nov 7, 2022 at 10:13
  • @Meow Could you share the full URL get an image or full data from the response? Commented Nov 7, 2022 at 10:56
  • @ChuongTran hi, I update the full data you can check the ReturnData image Commented Nov 8, 2022 at 2:36

2 Answers 2

0

Try the following to convert the binary data to base64 data.

res.end(res.data.toString('base64'));
Sign up to request clarification or add additional context in comments.

Comments

0

In order to show binary data on an img tag you could use URL.createObjectURL in your FE code to display the image

const imageSrc = URL.createObjectURL(res.data);
<img src=`${imageSrc}` />

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.