468,170 Members | 1,884 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,170 developers. It's quick & easy.

Return image link with webservice

Hello,

How can I return image link with webservice that I could see it in web page?
The image is on my hard disk and <img src="c:\pictures\test.jpg" /does not
work.
If I use <img src=http://My comuter/Virtual directory/test.jpg /it's
working but I can't use this because the image path is in DB with phisycal
location.

Thanks


Nov 8 '07 #1
3 5909
zion formulated the question :
Hello,

How can I return image link with webservice that I could see it in web page?
The image is on my hard disk and <img src="c:\pictures\test.jpg" /does not
work.
If I use <img src=http://My comuter/Virtual directory/test.jpg /it's
working but I can't use this because the image path is in DB with phisycal
location.

Thanks
The C:\ path won't work as that will always point to the local C: drive
for the browser, and that's not where your images are (and the
browser-machine might not even *have* a C: drive - unix doesn't!).

If you just want to return a link to the image from the webservice, add
a handler (ashx) to the webservice site that returns the image, based
on some image-id.
The URL returned from the webservice would then be something like
http://My Computer/theSite/ImageHandler.ashx?id=1234
This would look up the local path in your db, find the image-file and
return it using Response.WriteFile(..).

Hans Kesting
Nov 8 '07 #2
Thank you for reply.
Do you have any example for this solution?


"Hans Kesting" <in************@spamgourmet.comwrote in message
news:mn***********************@spamgourmet.com...
zion formulated the question :
>Hello,

How can I return image link with webservice that I could see it in web
page?
The image is on my hard disk and <img src="c:\pictures\test.jpg" /does
not
work.
If I use <img src=http://My comuter/Virtual directory/test.jpg /it's
working but I can't use this because the image path is in DB with
phisycal
location.

Thanks

The C:\ path won't work as that will always point to the local C: drive
for the browser, and that's not where your images are (and the
browser-machine might not even *have* a C: drive - unix doesn't!).

If you just want to return a link to the image from the webservice, add a
handler (ashx) to the webservice site that returns the image, based on
some image-id.
The URL returned from the webservice would then be something like
http://My Computer/theSite/ImageHandler.ashx?id=1234
This would look up the local path in your db, find the image-file and
return it using Response.WriteFile(..).

Hans Kesting


Nov 8 '07 #3
zion explained :
Thank you for reply.
Do you have any example for this solution?


"Hans Kesting" <in************@spamgourmet.comwrote in message
news:mn***********************@spamgourmet.com...
>zion formulated the question :
>>Hello,

How can I return image link with webservice that I could see it in web
page?
The image is on my hard disk and <img src="c:\pictures\test.jpg" /does
not
work.
If I use <img src=http://My comuter/Virtual directory/test.jpg /it's
working but I can't use this because the image path is in DB with phisycal
location.

Thanks

The C:\ path won't work as that will always point to the local C: drive for
the browser, and that's not where your images are (and the browser-machine
might not even *have* a C: drive - unix doesn't!).

If you just want to return a link to the image from the webservice, add a
handler (ashx) to the webservice site that returns the image, based on some
image-id.
The URL returned from the webservice would then be something like http://My
Computer/theSite/ImageHandler.ashx?id=1234
This would look up the local path in your db, find the image-file and
return it using Response.WriteFile(..).

Hans Kesting

public class ImageHandler : System.Web.IHttpHandler
{
// required by interface IHttpHandler
public bool IsReusable
{
get { return true; }
}

public void ProcessRequest(System.Web.HttpContext context)
{
int id = Int32.Parse(context.Request["id"]);
string filename = GetFilenameFromDatabase(id);
// need to implement this
// finds the full filename based on the supplied "id"

context.Response.ContentType = GetMimeTypeFromFilename(filename);
// need to implement this
// sets mimetype such as "image/jpeg"

context.Response.WriteFile(filename);
}
}
and in web.config, under <system.web>
<httpHandlers>
<add verb="GET" path="image.ashx" type="ImageHandler" />
</httpHandlers>

Note: the "type" value is the full classname (including namespace) of
your handler-class, optionally followed by a comma and the name of the
assembly it is defined in.

You can use it like <img src="http://server/image.ashx?id=1234">

Hans Kesting
Nov 8 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Nicolas | last post: by
4 posts views Thread by Nicolas | last post: by
2 posts views Thread by zion | last post: by
reply views Thread by kamranasdasdas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.