Ryan
Ryan

Reputation: 189

Download ZIP File from WCF - ASP.NET CORE

I'm accessing WCF service in ASP.NET core application which is returning content and file name in string format.

I want to download zip file from controller-action from data returned by service so written below code.

I can download the file but when try to open its prompting as invalid. Can someone help about the code.

var data = await someService.GetZipFile();

byte[] bytes = Encoding.ASCII.GetBytes(data.Content);

return File(bytes, "application/zip", data.FileName);

Upvotes: 1

Views: 588

Answers (1)

Nkosi
Nkosi

Reputation: 246998

In case the format of the string content is base64 string then try the following

public async Task<ActionResult> Download(...) {    
    var data = await someService.GetZipFile(...);

    String filename = data.FileName;
    String content = data.Content;

    //convert from base64 string
    byte[] bytes = Convert.FromBase64String(content);

    return File(bytes, "application/zip", filename);
}

Upvotes: 1

Related Questions