Base solution for your next web application

Activities of "mmorales"

Yes, it works if I'm on web browser. here is the public url https://lvnfapi01.digi360.us

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version? .NET Core 3.1 v8.7.0
  • What is your product type (Angular or MVC)? Angular
  • What is product framework type (.net framework or .net core)? .net core

If issue related with ABP Framework

  • What is ABP Framework version?

If issue is about UI

  • Which theme are you using? Default Metronic
  • What are the theme settings?

when making the from postman api/TokenAuthenticate call with multitenant I'm getting a user doest not excist. I have added the Abp.TenantId to the header but unfortunately the app does not authenticate. it seems that the host tenat is the only account that can authenticate.

Thanks a lot for your help I was finally able to get downloads to work for large files. I eded up using window.location.href=url; instead of location.href= url;

Thanks for your reply, after adding the enc_auth_token I get this error on the netcore end

INFO 2020-08-31 12:02:08,653 [37 ] uthorization.DefaultAuthorizationService - Authorization failed. INFO 2020-08-31 12:02:08,686 [37 ] tion.Cookies.CookieAuthenticationHandler - AuthenticationScheme: Identity.Application was challenged.

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version? v8.7
  • What is your product type (Angular or MVC)? angular
  • What is product framework type (.net framework or .net core)? netcore

If issue related with ABP Framework

  • What is ABP Framework version?

If issue is about UI

  • Which theme are you using?

I'm try to request a download genearting a url query string. i found angular code within the project (file-download helper)The second method is the one I created, when calling this method I get an auth error on the core side.( INFO 2020-08-27 16:54:58,612 [5 ] Microsoft.AspNetCore.Hosting.Diagnostics - Request starting HTTP/2 GET https://localhost:44301/FileManager/GetFile?fileName=lvweb01.zip&fileToken=6c3041bd-a1f6-1634-121d-f0252cb4cb3d INFO 2020-08-27 16:54:58,632 [5 ] uthorization.DefaultAuthorizationService - Authorization failed). Please advise **Angular ** export class FileDownloadService { downloadTempFile(file: FileDto) { const url = AppConsts.remoteServiceBaseUrl + '/File/DownloadTempFile?fileType=' + file.fileType + '&fileToken=' + file.fileToken + '&fileName=' + file.fileName; location.href = url; //TODO: This causes reloading of same page in Firefox } downloadFiles(fileName: string, fileToken: string) { const url = AppConsts.remoteServiceBaseUrl + '/FileManager/GetFile?fileName=' + fileName + '&fileToken=' + fileToken; location.href = url; //TODO: This causes reloading of same page in Firefox } } Core public async Task<FileStreamResult> GetFile(string fileName, string fileToken) { Stream stream = null; string filePath = Path.Combine(_env.WebRootPath, $"Common{Path.DirectorySeparatorChar}", $"Files{Path.DirectorySeparatorChar}", fileToken); stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);

    var fileStreaResult = new FileStreamResult(stream, "application/pdf");
    fileStreaResult.FileDownloadName = fileName;
    return fileStreaResult;
}

I found angular code within the project (file-download.service.ts). The second method is the one I created, when calling this method I get an auth error on the core side.( INFO 2020-08-27 16:54:58,612 [5 ] Microsoft.AspNetCore.Hosting.Diagnostics - Request starting HTTP/2 GET https://localhost:44301/FileManager/GetFile?fileName=lvweb01.zip&fileToken=6c3041bd-a1f6-1634-121d-f0252cb4cb3d
INFO 2020-08-27 16:54:58,632 [5 ] uthorization.DefaultAuthorizationService - Authorization failed). Please advise

**Angular ** export class FileDownloadService {

downloadTempFile(file: FileDto) {
    const url = AppConsts.remoteServiceBaseUrl + '/File/DownloadTempFile?fileType=' + file.fileType + '&fileToken=' + file.fileToken + '&fileName=' + file.fileName;
    location.href = url; //TODO: This causes reloading of same page in Firefox
}
downloadFiles(fileName: string, fileToken: string) {
    const url = AppConsts.remoteServiceBaseUrl + '/FileManager/GetFile?fileName=' + fileName + '&fileToken=' + fileToken;
    location.href = url; //TODO: This causes reloading of same page in Firefox

}

} Core public async Task<FileStreamResult> GetFile(string fileName, string fileToken) { Stream stream = null;

        string filePath = Path.Combine(_env.WebRootPath, $"Common{Path.DirectorySeparatorChar}",        $"Files{Path.DirectorySeparatorChar}", fileToken);

        stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
     
        var fileStreaResult = new FileStreamResult(stream, "application/pdf");

        fileStreaResult.FileDownloadName = fileName;

        return fileStreaResult;

    }

Prerequisites

Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • What is your product version? v8.70
  • What is your product type (Angular or MVC)? Angular
  • What is product framework type (.net framework or .net core)? .net core 3.1

If issue related with ABP Framework

  • What is ABP Framework version?

If issue is about UI

  • Which theme are you using?
  • What are the theme settings?

I'm trying to download large files with the following code which returns a blob from .netcore 3.1

downloadFile(id): void {

        let filedownloadInput = new FileDownloadInput();
        filedownloadInput.id = id;

        this._FileManagerService.downloadFile(filedownloadInput).subscribe(item => {
             this.InitializeDownload(item.fileName, item.fileToken).subscribe((data: any) => {

                 
                var downloadURL = window.URL.createObjectURL(data);
                var link = document.createElement('a');
                link.href = downloadURL;
                link.download = item.fileName;
                link.click();

            });
        });
    }
    

This works for small files (<10mb) but when large files are inbound, the response being saved to browser memory takes too long. I know that this method doesn't save directly to the filesystem, as it passes through the browser first, but is there a way to bypass saving the entire blob to browser memory first? So it seems like the browser caches the file first at which point the user does'nt see anything. You can only see the transfer with dev tools. Once it downloads to the browser memory then I can see the file downloading on the browser.

Hello @musa.demir

I have the below method. The problem is that when I execute the download method it takes a long time to actually see the file start downloading on my screen. After further looking at development tools when executing downloadFile method I see the content in the background transferring as seen below.

once the transfer is complete the code under subscribe executes and I can see the actual file downloading as below

Please advise. I haven't been able to figure how to skip the transfer content as it seems redudant to perform the content transfer and the download.

downlodFile(id): void {

let filedownloadInput = new FileDownloadInput();
filedownloadInput.id = id;

this._FileManagerService.downloadFile(filedownloadInput).subscribe(item => {
     this.InitializeDownload(item.fileName, item.fileToken).subscribe((data: any) => {

        this.blob = new Blob([data], { type: 'application/pdf' });

        var downloadURL = window.URL.createObjectURL(data);
        var link = document.createElement('a');
        link.href = downloadURL;
        link.download = item.fileName;
        link.click();

    });
});

} InitializeDownload(fileName:string, fileToken:string) { const url = AppConsts.remoteServiceBaseUrl + '/FileManager/GetFile'; this.token = this._tokenService.getToken(); let params = new HttpParams();

params = params.append('fileName', fileName);
params = params.append('fileToken', fileToken);
const httpOptions = {
    responseType: 'blob' as 'json',
    headers: new HttpHeaders({
        "Authorization": "Bearer " + this.token
    }),
    params: params
};

return this._httpClient.get(url, httpOptions);

}

this was generated with the refresh.bat command.

/**
 * @param body (optional) 
 * @return Success
 */
downloadFile(body: FileDownloadInput | undefined): Observable<FileDownloadOutput> {
    let url_ = this.baseUrl + "/api/services/app/FileManager/DownloadFile";
    url_ = url_.replace(/[?&]$/, "");

    const content_ = JSON.stringify(body);

    let options_ : any = {
        body: content_,
        observe: "response",
        responseType: "blob",			
        headers: new HttpHeaders({
            "Content-Type": "application/json-patch+json", 
            "Accept": "text/plain"
        })
    };

    return this.http.request("post", url_, options_).pipe(_observableMergeMap((response_ : any) => {
        return this.processDownloadFile(response_);
    })).pipe(_observableCatch((response_: any) => {
        if (response_ instanceof HttpResponseBase) {
            try {
                return this.processDownloadFile(<any>response_);
            } catch (e) {
                return <Observable<FileDownloadOutput>><any>_observableThrow(e);
            }
        } else
            return <Observable<FileDownloadOutput>><any>_observableThrow(response_);
    }));
}

protected processDownloadFile(response: HttpResponseBase): Observable<FileDownloadOutput> {
    const status = response.status;
    const responseBlob = 
        response instanceof HttpResponse ? response.body : 
        (<any>response).error instanceof Blob ? (<any>response).error : undefined;

    let _headers: any = {}; if (response.headers) { for (let key of response.headers.keys()) { _headers[key] = response.headers.get(key); }};
    if (status === 200) {
        return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
        let result200: any = null;
        let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
        result200 = FileDownloadOutput.fromJS(resultData200);
        return _observableOf(result200);
        }));
    } else if (status !== 200 && status !== 204) {
        return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
        return throwException("An unexpected server error occurred.", status, _responseText, _headers);
        }));
    }
    return _observableOf<FileDownloadOutput>(<any>null);
}

    public async Task&lt;FileDownloadOutput&gt; DownloadFile(FileDownloadInput input)
    {
       var fileInfo = await _filesObjectsRepository.FirstOrDefaultAsync(c => c.Id == input.Id);

        var output = new FileDownloadOutput()
        {
            FileName = fileInfo.FileName,
            FileToken = fileInfo.Identifier
        };

        return output;
       
    }
Showing 1 to 10 of 27 entries