question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

why I can't download file in my AppService layer in abp?

See original GitHub issue
[HttpGet]
[DontWrapResult]
public async Task DownloadCertificateFile(string companyDLRef)
{
	var certificatePath = await SettingManager.GetSettingValueAsync(SettingKeyConstants.ExternalServices.Support.CertificatePath);
	var certificateFolder = HostingEnvironmentAccessor.MapPath(certificatePath);
	if (string.IsNullOrEmpty(companyDLRef) == false)
	{
		var allowedExtensions = new[] { ".jpeg", ".jpg", ".png", ".pdf" };
		var files = Directory
		.GetFiles(certificateFolder, companyDLRef + "*")
		.Where(file => allowedExtensions.Any(file.ToLower().EndsWith))
		.ToList();
		if (files.Any())
		{
		   var file = files.First();

			HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
			var fileStream = new FileStream(file, FileMode.Open);
			response.Content = new StreamContent(fileStream);
			response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
			response.Content.Headers.ContentDisposition.FileName = Path.GetFileName(file);
			response.Content.Headers.ContentType = HasPdfExtension(file)? new MediaTypeHeaderValue("application/pdf") : new MediaTypeHeaderValue("image/png");
			return response;
		}

	}
	return new HttpResponseMessage();
}

Result is a json data:

{
    "version": {
        "major": 1,
        "minor": 1,
        "build": -1,
        "revision": -1,
        "majorRevision": -1,
        "minorRevision": -1
    },
    "content": {
        "headers": [
            {
                "key": "Content-Disposition",
                "value": [
                    "attachment; filename=220006.jpg"
                ]
            },
            {
                "key": "Content-Type",
                "value": [
                    "image/png"
                ]
            }
        ]
    },
    "statusCode": 200,
    "reasonPhrase": "OK",
    "headers": [],
    "requestMessage": null,
    "isSuccessStatusCode": true
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
hikalkancommented, Dec 23, 2018

Return Task<FileResult> or Task<ActionResult> from your method.

0reactions
hikalkancommented, Apr 29, 2019

Then create a controller in your web layer and internally use the app layer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to download large file #1528 | Support Center
Another issue I found when trying Abp version 4.3.2, the downloaded file size is 0kb when downloading the large file (around ~500mb and ......
Read more >
File Upload/Download with BLOB Storage System in ASP.NET ...
This step-by-step article describes how to upload a file to a Web server and also download by client with using ASP.NET Core &...
Read more >
File Upload/Download with BLOB Storage System in ASP. ...
This step-by-step article describes how to upload a file to a Web server and also download by client with using ASP.NET Core &...
Read more >
Angular 6 Downloading file from rest api - typescript
In My service I have: public getPDF(): Observable<Blob> { //const options = { responseType: 'blob' }; there is no use of this let...
Read more >
ABP Framework — Web Application Development Tutorial ...
This video is based on this tutorial: https://docs. abp.io/en/ abp /latest/Tutorials/Part-1?UI=MVC&DB=EF 00:00 Introduction 01:07 Creating the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found