aadsm / JavaScript-ID3-Reader

ID3 tags reader in JavaScript (ID3v1, ID3v2 and AAC)

Home Page:http://www.aadsm.net/libraries/id3/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Showing cross origin error in access of another domain mp3 files tags

php07magic opened this issue · comments

I am trying to fetch all tags data like album name, artist, song image etc from amazon server. Here is one URL of song that I am passing https://s3.amazonaws.com/clueradiomedia/music/%24uicideBoy%24/Either%20Hated%20Or%20Ignored%20-%20Single/Either%20Hated%20Or%20Ignored.mp3

var customurl = 'https://s3.amazonaws.com/clueradiomedia/music/%24uicideBoy%24/Either%20Hated%20Or%20Ignored%20-%20Single/Either%20Hated%20Or%20Ignored.mp3';

ID3.loadTags(customurl, function() {

    var getfile = customurl;
	var tags = ID3.getAllTags(getfile);
	
	console.log(tags);
	
	alert(tags.artist + " - " + tags.title + ", " + tags.album);

	var image = tags.picture;
	if (image) {
		var base64String = "";
		for (var i = 0; i < image.data.length; i++) {
			base64String += String.fromCharCode(image.data[i]);
		}
		var base64 = "data:" + image.format + ";base64," +
				window.btoa(base64String);
		document.getElementById('picture').setAttribute('src',base64);
	  } else {
		document.getElementById('picture').style.display = "none";
	  }
},{
    tags: ["title","artist","album","picture", "year", "comment", "track", "genre", "lyrics"],
  });

But, when I am hitting above function then its showing me this error "Access to XMLHttpRequest at 'http://s3.amazonaws.com/clueradiomedia/music/%24uicideBoy%24/Either%20Hated%20Or%20Ignored%20-%20Single/Either%20Hated%20Or%20Ignored.mp3' from origin 'http://----' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."

I am checking the main file but its minified so I can't deduct how to pass request headers for XML request.

Can please suggest me how to pass allow origin headers here?

Thanks!

Hey @php07magic,

CORS is something that is configured on the server, not on the client. The server needs to send the Access-Control-Allow-Origin so the browser knows it’s fine to connect to it.
I haven’t used amazon to store files myself but I’d imagine it should be possible to configure that. They talk about it here: https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html.