I'm still new to Angular and we have a bug related to downloading files - one of the pages has a grid with files that are downloaded to PC when clicked on. However, when the files are downloaded weirdly, like this:
I don't understand what kind of format that is. For example, I upload a .pdf file and when it downloads the file like and I try to open it, Windows asks me which program I want to use open it. The files don't get corrupt because I can open them with the correct program but if the file is a PDF or TXT, I want it to download exactly like that. We use the same method for saving and downloading files in the main ASP.NET web app and all files are downloaded normally there.
Saving document:
this.dataService
.saveItemAndGetId('api/documents-medicine/save', data)
.finally(() => {
this.loaderR = false;
this.addNewResolved.emit(true);
this.removeClickedElement();
})
.subscribe(
res => this.sharedService.handleSaveResponse(res > 0 ? true : false, this.localization.translate('documents'), '/app/documents/' + this.sharedService.globals.selectedResident.id),
err => this.sharedService.handleError(err)
);
Document download:
this.dataService
.getFile('api/documents-medicine/' + data[1].id)
.subscribe(
res => window['saveAs'](res, data[1].fileName),
err => this.sharedService.handleError(err)
)
.getFile service:
DocumentModel model = this.repository.getResidentSingleDocument(id);
if (model != null)
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(model.DocumentData);
return result;
}
return new HttpResponseMessage(HttpStatusCode.BadRequest);
"getResidentSingleDocument" method in repository:
try
{
return this.ctx.ResidentDocuments.Where(it => it.ID == Id)
.Select(it => new DocumentModel
{
Title = it.Titel,
DocumentData = it.ResidentDocument,
CreatedBy = it.CreatedBy
}).SingleOrDefault();
}
catch (Exception Ex)
{
throw Ex;
}