Niko
Niko

Reputation: 251

Return Base64 Encoded Image As HTTP Response in C#

I have a webservice and in this particular case I have an image encoded in base64 that I would like to return as a string included in the http response body. I have tried to add the following headers:

Content-Type: image/gif

Content-Transfer-Encoding: base64

The browser doesn't interpreted the image correctly though.

Is it possible to return a base64 encoded image as a string in the body and have the browser interpret it as an image?

Upvotes: 0

Views: 2729

Answers (2)

Julian Reschke
Julian Reschke

Reputation: 42017

There is no Content-Transfer-Encoding in HTTP. Just return the binary data.

Upvotes: 1

mybirthname
mybirthname

Reputation: 18127

Response.ContentType = attachmentRow["ContentType"].ToString();
Response.BinaryWrite((byte[])attachmentRow["Data"]);                
Response.End();

This should be enough.

attachmentRow["ContentType"] = "image/gif";
attachmentRow["Data"] field of type image(byte array) in your AttachmentTable.

Upvotes: 1

Related Questions