-1

I have base64 string of an image. converting it to byte array & then converting it to memoryStream. How can i download this image to client machine. The base64 string or image is not saved on server/folder/anywhere. It is create dynamically. I have tried

1) Response.ContentType = "image/png" => gives exception obj not set to instant of an object. like this

Context.Response.Clear();
Context.Response.ClearHeaders();
Context.Response.AddHeader("Content-Disposition", "attachment; filename=" + registrationId + ".png");
Context.Response.ContentType = "image/jpeg";
Response.AddHeader("Content-Length", bytes.Length.ToString());
//Response.ContentType = "application/octet-stream";
Context.Response.BinaryWrite(bytes);

2) using web client => gives exception

using (WebClient client = new WebClient())
{
    client.DownloadFile(ms1.ToString(), registrationId + ".png");
}

Any other solution?

Mohit S
  • 13,723
  • 6
  • 34
  • 69

1 Answers1

0

Just try to change

Response.AddHeader("Content-Length", bytes.Length.ToString());

to

Context.Response.AddHeader("Content-Length", bytes.Length.ToString());

I think you doesn't have valid Page object in this context.

GraDea
  • 588
  • 7
  • 23