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

Endpoint for get image directly #40

Open
cncolder opened this issue Aug 31, 2022 · 1 comment
Open

Endpoint for get image directly #40

cncolder opened this issue Aug 31, 2022 · 1 comment

Comments

@cncolder
Copy link

Currently, all endpoints responds a json. Is there a way to get the image directly?

e.g. https://dog.ceo/api/breeds/image/random.jpg

So that we can embed in markdown:

![](https://dog.ceo/api/breeds/image/random.jpg)
@iamabhshk
Copy link

const axios = require('axios');
const url = 'https://dog.ceo/api/breeds/image/random.jpg';
axios.get(url, { responseType: 'blob' })
  .then((response) => {
    if (response.status === 200) {
      const blob = response.data;
      const image = document.createElement('img');
      image.src = URL.createObjectURL(blob);
      document.body.appendChild(image);
    } else {
      console.log('Error getting image.');
    }
  })
  .catch((error) => {
    console.log(error);
  });

Hope, I answered your question

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants