0

I'm downloading a zip file using Angular with a GET request but it gives me a CORS problem due to incompatibility of domains. Calling the URL directly from browser gets me to download the zip file I need.

For example, this would be a URL that downloads a file: https://serv-platform-dev.myhost.system/DOWNLOADS/20230217_095914_files_download.zip (the domain cannot change the rest yes)

This is my Angular service where I make the GET request:

// url variable will be for example: https://serv-platform-dev.myhost.system/DOWNLOADS/20230217_095914_files_download.zip    
getDownloadFile(url: string): Observable<any> {
        return this.http.get(url, {observe: 'response', responseType : 'blob'}); 
    }

I know that several "targets" can be configured in my Angular proxy file, I already have one that is to access the APIs under port 8080, but now I need to configure another domain, which is where the zip files that I need to download.

This is my "proxy.conf.js" file:

const TARGET_URL1 = "http://localhost:8080/";
const TARGET_URL2 = "https://serv-platform-dev.myhost.system/";
const PROXY_CONFIG = {
    "/files": {
        "target": TARGET_URL1,
        //"target": "http://localhost:9292/", //MOCK
        "secure": false,
        "changeOrigin": true,
        "logLevel": "debug"
    },
    "/download": {
        "target": TARGET_URL2,
        "secure": false,
        "changeOrigin": true,
        "logLevel": "debug"
    }
}

The configuration for requests under "TARGET_URL1" works correctly. But I don't know what I have to do in my Angular service or whatever to get the permission to make requests to "TARGET_URL2" and not get the Cors problem"

NOTE: I am doing a test to use the download route "/download" and concatenate the dynamic content of the url for the GET, maiby I solve it with this.

Any idea?

Eladerezador
  • 1,277
  • 7
  • 25
  • 48
  • 1
    Does this answer your question? [Response to preflight request doesn't pass access control check](https://stackoverflow.com/questions/35588699/response-to-preflight-request-doesnt-pass-access-control-check) –  Feb 17 '23 at 11:50

0 Answers0