Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

668
Views
cómo leer encabezados de disposición de contenido de la respuesta del servidor angular 2

No puedo encontrar cómo leer el nombre del archivo desde la disposición del contenido en la documentación angular 2. ¿Alguien puede guiar a leer los encabezados del servidor en los encabezados de contenido angular 2?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Con el nuevo Angular Http, se puede probar lo siguiente en el código de servicio.

 downloadLink(): Observable<HttpResponse<Blob>> { return this.http.get<Blob>(this.someURL, { observe: 'response', responseType: 'blob' as 'json' }); }

Y usa lo anterior como

 this.someService .downloadLink() .subscribe( (resp: HttpResponse<Blob>) => { console.log(resp.headers.get('content-disposition')); data = resp.body });

Además, en el lado del servidor, es necesario configurar el siguiente encabezado en respuesta. 'Access-Control-Expose-Headers': 'Content-Disposition'

Al igual que en Java Spring Boot, se puede hacer lo mismo usando

 final HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=1.xlsx"); headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);
over 4 years ago · Santiago Trujillo Report

0

Para aquellos que se quejan de que la mejor solución no funciona, y solo el tipo de contenido está en los encabezados, debe configurar 'Access-Control-Expose-Headers': 'Content-Disposition' EN EL LADO DEL SERVIDOR. Estoy usando asp.net core, luego tengo que hacer lo siguiente.

 app.UseCors(builder => builder.WithOrigins(originsAllowed.ToArray()) .AllowAnyMethod() .AllowAnyHeader() .WithExposedHeaders("Content-Disposition")
over 4 years ago · Santiago Trujillo Report

0

Puedes probar este tipo de código aquí.

Nota: No utilice el mapa

 this.http.post(URL, DATA) .subscribe((res) => { var headers = res.headers; console.log(headers); //<--- Check log for content disposition var contentDisposition = headers.get('content-disposition'); });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!