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

374
Views
Cómo devolver la respuesta con ng2-file-upload

Estoy usando ng2-file-upload en angular 4. ¿Hay alguna forma de devolver datos personalizados desde el servidor? ¿Cómo accederíamos a él en el archivo ts?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debería usar uploader onSuccessItem y onErrorItem callbacks:

 import { Component } from '@angular/core'; import {FileUploader, FileItem, ParsedResponseHeaders} from "ng2-file-upload"; @Component({ selector: 'upload-file', template: ` <input type="file" ng2FileSelect [uploader]="uploader"> `, }) export class UploadFileComponent { uploader:FileUploader; ngOnInit(): void { this.uploader = new FileUploader({ url: 'http://url.to/upload', headers: [{name:'Accept', value:'application/json'}], autoUpload: true, }); this.uploader.onErrorItem = (item, response, status, headers) => this.onErrorItem(item, response, status, headers); this.uploader.onSuccessItem = (item, response, status, headers) => this.onSuccessItem(item, response, status, headers); } onSuccessItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any { let data = JSON.parse(response); //success server response } onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any { let error = JSON.parse(response); //error server response } }

about 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!