I encounter with next problem:I configure in asp.net azurite and i can successfully upload and get image from it,this image is successfully renders in browser,but when i put this url in img tag in my angular app,i encounter error:Failed to construct 'URL': Invalid URL.
I tried to use encodeURIComponent function to construct my url
var encodedContainerName = encodeURIComponent("");
var encodedBlobName = encodeURIComponent("");
this.imageUrl = "http://127.0.0.1:10000/devstoreaccount1/" + encodedContainerName + "/" + encodedBlobName;
But problem persists
The error you're seeing (
Failed to construct 'URL': Invalid URL) typically suggests that the value being passed into a URL object or similar function is not in a correct URL format.From the example you've given:
Both
encodedContainerNameandencodedBlobNameare empty. So, this might be the root cause of your problem.Ensure you're assigning values to your container name and blob name:
If this still doesn't solve the problem, consider the following:
CORS Configuration: Ensure that Azurite has been configured correctly to allow cross-origin requests from your Angular application's domain.
Content Delivery: Sometimes, the way content is served matters. If the content type of the image isn't being sent correctly, browsers can reject loading them. Ensure that Azurite is sending the appropriate content headers.
URL Verification: After constructing your URL, log it (
console.log(this.imageUrl)) and manually check if the URL is correct. Try accessing this URL directly in the browser.Alternative Image Tags: Instead of binding the URL directly to the
srcof the<img>tag, try using Angular's binding:DomSanitizerfor this:Then, in your template:
Remember, bypassing Angular's built-in security checks can expose your application to various vulnerabilities, so always be sure of what URLs you're sanitizing and loading into your application.