Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

If one visits jQuery-File-Upload Demo page and will try to upload an image, and then will look at the JSON response, he would notice that a preview of an uploaded image is returned in a format:

"thumbnail_url":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAI...

As far as I understand, an images is getting transformed into string and sent back to the client.

How can I do it in C# to impelement ASP.NET back end for the same demo?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
474 views
Welcome To Ask or Share your Answers For Others

1 Answer

I remember reading an answer to a question a while back by the very competent competent_tech and thinking "I never knew you could do that!"

In that answer is an example about how to set the src of an ASP.Net image to be the base64 encoded data you see above.

It effectively boils down to setting the src of an ASP:Image control as follows:

imgCtrl.Src = @"data:image/gif;base64," + Convert.ToBase64String(File.ReadAllBytes(Server.MapPath(@"/images/your_image.gif")));

Remember to change the content type depending on the image!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...