4

I have a byte array of an image on the server side. I have an img tag on my View page.

I'm wondering how to be able to use the byte array as the image source of the img tag.

I'm retrieving the byte array in my model, passing it back to my controller method and then I'd like to store it in ViewData somehow. Then in the $(document).ready jQuery function of the View page somehow set that byte array as the source for my IMG tag.

Is this possible?

2 Answers 2

5

You should be able to do it. Just convert the byte array to a string of base64 digits and than set the the imge src attribute to the encoded image. See this question and answer.

Sign up to request clarification or add additional context in comments.

Comments

0

No. Images can't be rendered in this way. An image must be passed to a browser as a singular file with an appropriate mime-type and then referenced through a url. If you have the byte array of an image in a database or similar structure, your best bet is to access this data through a pass-through page specifically designed to respond with the proper headers and mime-type (perhaps an ASHX handler would suit this usage nicely).

3 Comments

This is not correct. You can use a data URI and pass the image in the HTML. en.wikipedia.org/wiki/Data_URI_scheme
@Jace Rhea: With extremely limited results. I will concede that it is POSSIBLE, if you will concede that it is very limited.
@ Joel Etherton: I concede it is very limited. I believe IE will have problems with this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.