473,396 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 6100
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Scott | last post by:
I am storing an image in an SQL database and have one field as an image datatype. I am also using a webservice to transport data. I want to be able to resize the image and pass back a thumbnail...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
13
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't...
0
by: Geert | last post by:
Hi all, I have a webservice that creates an image. I want to show the result of that image on my website. The website and webservice are on different servers. There is a VPN line between both...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
2
by: Nicolas | last post by:
Hello! I have a question: I have a database in MySql that has two fields (code and image). Now, I want to create a WebService that takes the image of the most current row (the code is the date...
4
by: Nicolas | last post by:
Hello! I have a question: I have a database in MySql that has two fields (code and image). Now, I want to create a WebService that takes the image of the most current row (the code is the date...
2
by: zion | last post by:
Hi, I have database with picture locations, for example: c:\temp\test.jpg. How can webservice return picture link? <img width=200 height=150 src='file://c:\\temp\\test.jpg' /> <img width=200...
2
by: ksheerasagar17 | last post by:
Hello All, Scenario: Sending an image through webservice as byte array to an Java webservice. The Problem1: The webservice method image property expects (data type) SByte rather than Byte...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.