-1

I have a discord message that have an attachment. This attachment is a blob file, that have html code inside. I need to get a raw response text, because it have html code inside. When I try to fetch it, it says "Access-Control-Allow-Origin Missing Header" with CORS, but in Postman I have what I need. How to get a html text from url that download blob file?

fetch("https://cdn.discordapp.com/attachments/924478995830013995/1026201687628718112/blob")
    .then(response => response.text())
    .then(result => console.log(result))
    .catch(error => console.log('error', error));

Link is real, so you can download this blob file and add a .html file extension, also you can test that Postman get a html code well.

kanezal
  • 1
  • 2
  • 1
    The server you’re attempting to call is configured with CORS headers to disallow cross-domain requests from end users’ browsers. Unless you control the server, you won’t be able to access this URL from in-browser JavaScript without something like an intermediary proxy. – esqew Oct 03 '22 at 18:59
  • Please research your inquiry before posting in accordance with [ask]. Duplicate of [CORS header 'Access-Control-Allow-Origin' missing](https://stackoverflow.com/questions/31276220/cors-header-access-control-allow-origin-missing) – esqew Oct 03 '22 at 19:00

1 Answers1

-1

"Access-Control-Allow-Origin Missing Header" with CORS means you have to provide the header key mode which will be cors by default. Here you have to provide the mode as no-cors to support the cross-origin requests.

Secondly, You have to return the response as response.blob() to download the file attachement.

  • This solution does not satisfy the requirements of the OP. MDN explicitly mentions that `no-cors` will disallow JavaScript from accessing any properties of the resulting `Response`. [Source](https://developer.mozilla.org/en-US/docs/Web/API/Request/mode#value) – esqew Oct 03 '22 at 18:56
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 08 '22 at 15:47