Link to home
Start Free TrialLog in
Avatar of ZekeLA
ZekeLAFlag for United States of America

asked on

Best way to get database images from Web Service

I'm working on a mobile web site and web service where the images are stored in the database. For the web site, I'm using the following markup to display a stored image:
<img id="MyImage" runat="server" EnableViewState="false"
    src='<%# Eval("ImageFileID", "~/HttpHandlers/DBImageHandler.ashx?fileid={0}") %>' alt=""
/>

Open in new window


But other web sites may call my web service and need access to the stored images. Should I just have the web method return the ResolveURL value of "~/HttpHandlers/DBImageHandler.ashx?fileid={0}" or is there a better way?

Or is it sufficient if I just return the ImageFileID and document how the caller should make use of that information?

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Why don't you create a WebMethod in WebService which takes the Id from client to retrieve image from database. And then return the byte array of the image back to the client. And on the client side in your web application use those byte array values in MemoryStream to retrieve image from the same.

Why ? Because no need of providing clients the URL as some of malicious user can misuse them. (It's my assumption only, your choice to accept it or not).

Regards,
VSS
Avatar of ZekeLA

ASKER

That's what I meant to say MlandaT when i said I would use ResolveURL. I realize I have to give them the rendered URL. I appreciate the confirmation.

VSS, that's what the handler does. But the client could be almost anything; it won't necessarily be be .NET. How well can other platforms take an array of bytes back and convert it into an image?
Avatar of ZekeLA

ASKER

My other issue was making the web method result small. Returning just the FileID is less than providing the entire url. But it requires the client to create the image's url. And it isn't flexible if our website organization changes. I could always put the base url in a returned soap header so it only gets sent once per call.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial