如何显示位于网络上另一台服务器上的图像 (ASP.NET)

发布于 2024-08-28 10:40:01 字数 727 浏览 7 评论 0原文

我有一个位于本地服务器 (MY_SERVER) 上的 ASP.NET 站点。它所做的事情之一就是提取位于另一台服务器(ANOTHER_SERVER)上的 tiff 文件。每个文件的位置都存储在 SQL 中。我提取这些图像中的每一个并应该显示它们。问题是:

  1. 文件没有以 tiff 扩展名命名(这重要吗?)

  2. 它们没有显示在全部。

我正在使用图像控件来显示这些图像,并且我不确定未设置扩展名是否重要(图像控件是否知道 jpg 和没有扩展名的 tiff 之间的区别?)

我猜测图像未显示,因为它们不在图像所在的同一服务器 MY_SERVER (ANOTHER_SERVER) 上。关于如何解决这个问题有什么想法吗?

编辑:实际上显示 tiff 文件非常简单:

protected void Page_Load(object sender, EventArgs e)
{
    Response.ContentType = "image/png";
    new Bitmap(Request.QueryString["ImagePath"]).Save(Response.OutputStream, ImageFormat.Gif);

}

但由于图像位于 ANOTHER_SERVER 上,我仍然无法访问它们。我可能只是做了一个 hack,将它们复制到 MY_SERVER 上的本地目录,但必须有一个简单的方法来解决这个问题。有人吗?

I've got a ASP.NET site that's located on a local server (MY_SERVER). And one of the things it does is pull up tiff files which are located on another server (ANOTHER_SERVER). The location of each of these files is stored in SQL. I pull up each of these images and am supposed to display them. The problem is:

  1. the files are not named with a tiff extension (does it matter?)

  2. they aren't displaying at all.

I am using an Image control to display these images, and I'm not sure if it matters that the extension is not set (does the image control know the difference between an jpg and a tiff without the extension?)

I am guessing the images aren't displaying because they are not on the same server MY_SERVER that the images are located (ANOTHER_SERVER). Any ideas on how to fix this?

edit: actually displaying the tiff files were amazingly simple:

protected void Page_Load(object sender, EventArgs e)
{
    Response.ContentType = "image/png";
    new Bitmap(Request.QueryString["ImagePath"]).Save(Response.OutputStream, ImageFormat.Gif);

}

but because the images are located on ANOTHER_SERVER I still can't access them. I may just do a hack where I copy them to a local directory on MY_SERVER but there's gotta be a simple way to fix this. Anyone?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

滥情稳全场 2024-09-04 10:40:01

ANOTHER_SERVER 上的图像是否可以通过 HTTP 访问,或者您是否尝试使用其 UNC 路径在 img 标记中显示它们?

由于网页是在客户端计算机上查看的,因此必须可以从客户端计算机访问资源(图像/css/脚本等)的路径。即使可以从服务器访问它们,如果不能从客户端访问它们,它们也将不可见。

我怀疑在这种情况下 MY_SERVER 可以访问 ANOTHER_SERVER 上的 tiff,但是 ANOTHER_SERVER 的路径对于访问该页面的客户端来说没有任何意义。

您需要从磁盘读取图像并使用客户处理程序将其显示为图像,或者通过 HTTP 在 ANOTHER_SERVER 上公开图像并以这种方式引用它们(这意味着客户端必须能够直接连接到 ANOTHER_SERVER) 。

Are the images on ANOTHER_SERVER accessible via HTTP or are you trying to display them in an img tag using their UNC path?

Since web pages are viewed on client machines, the paths to resources (images/css/scripts etc) must be accessible from the client's machine. Even if they are accessible from the server, if they aren't accessible from the client they won't be viewable.

I suspect in this instance MY_SERVER can access the tiffs on ANOTHER_SERVER, however the path to ANOTHER_SERVER means nothing to the client accessing the page.

You will either need to read the image in from the disk and display it as an image using a customer handler, or expose the images on ANOTHER_SERVER via HTTP and reference them that way (which means the client must be able to directly connect to ANOTHER_SERVER).

所有深爱都是秘密 2024-09-04 10:40:01
  1. 无论您使用什么标签,ANOTHER_SERVER 是否会将图像存储在可访问互联网的位置?如果没有,您就无法直接在互联网上为它们提供服务。您可以尝试使用 Response.WriteFile 下载文件。
  2. 标签并不旨在提供 TIFF。 QuickTime 插件是一个免费的 TIFF 查看器,但它不是很灵活。在我工作的地方,我们使用 Atalasoft 的 dotImage,它将 TIFF 转换为平铺的 PNG飞,但它不是免费的。我找到了这篇 CodeProject 文章。即使您可以将图像转换为 Web 友好的格式,您的服务器端代码也可能必须在 Web 服务器上缓存该文件。
  1. Regardless of what tag you use, does ANOTHER_SERVER store the images in an internet accessible location? If not, you cannot serve them directly on the internet. You can try downloading the file with Response.WriteFile.
  2. The <img /> tag is not meant to serve TIFFs. The QuickTime plugin is a free TIFF viewer, but it is not very flexible. Where I work, we use Atalasoft's dotImage, which converts TIFFs to tiled PNG on the fly, but it is not free. I found this CodeProject article. Even if you can transform the image into a web-friendly format, your server-side code might have to cache the file on the web server.
寄居人 2024-09-04 10:40:01

如果您的 img 标签 src 设置正确并且服务器可访问,您应该能够显示来自另一台服务器的图像。不过,我不相信大多数浏览器都支持直接查看 tiff 文件。有许多可用的 tiff 查看器 (谷歌搜索)。

您也可以尝试使用 标记,看看它是否有效 (看这里)。用户的计算机必须知道如何处理冲突。

You should be able to display an image from another server if your img tag src is properly setup and the server is accessible. However, I don't believe that most browsers support directly viewing tiff files. There are a number of tiff viewers available (google it).

You might also try an <embed> tag and see if it does the trick (look here). The user's computer would have to know how to deal with tiffs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文