Linking images from other websites in <img> tags, with URL's returned from my Django API. Is this a sustainable approach for production?
Will I run into a CORS error if I am using my API to return an image url, from on another site, which I set to an tag with the src attribute?
I have an API written in Django which has a model with links to movie posters, which are hosted on the site: m.media-amazon.com, for example:
With my current development server, I have a JavaScript file that makes a request to an endpoint which returns that url, which I then set in an img tag with the src attribute. It displays in my browser, but will I run into issues in production? is this a sustainable approach?
this is my js code:
async function getMovieUrl() {
try {
const response = await fetch('/posterurl/',
{
method: 'GET'
});
const urldata = await response.json()
var url = document.getElementById("posterurl")
url.src = urldata['url']
} catch(error) {
console.error(error)
}
}
this is my API code:
@api_view(['GET'])
def poster_url(request):
context = {'url': url from above}
return Response(context)
and currently I am able to see the image in my browser upon clicking:
<button onclick="getMovieUrl()">Movie URL</button>