Reputation: 1231
I got my pictures on an ftp server, on my network, which i want to display on my website.
How can that be done?
Earlier i used ("/Boats/{BoatId}/{ImageId} + "." + {ImageExtension")
but now i have my pictures on \\ftplocation\files\boatcompany\boats\
I tried the following: (Works with the url above).
ImageUrl='<%# String.Format(@"\\ftp\files\boatcompany\boats\{0}\thumbnails\{1}.{2}", Eval("BoatId"), Eval("Image.ImageId"), Eval("Image.Extension")) %>' />
Upvotes: 0
Views: 2437
Reputation:
In addition to Max's answer I wanted to add a third solution that works with both private and public ftp servers (and anything else really).
What you need to do is use your application as a proxy for the ftp.
Then you can do this (line breaks to make it more readable):
ImageUrl = '<%#
String.Format(@"/getimage.aspx?boatid={0}&imageid={1}&extension={2}",
Eval("BoatId"),
Eval("Image.ImageId"),
Eval("Image.Extension")) %>'
For FTP you can use the built-in capabilities in .net or use a third-party extension such as Rebex-FTP which makes streaming files from ftp a walk in the park.
Using a page to retrieve pictures this way makes it capable of obtaining images from various sources, not just ftp, at the same time keeping it transparent for the user.
Upvotes: 3
Reputation: 3770
Because of security issues browsers will never load any resources (including images) from local storage. So, URLs like \\server\myfile.jpg
or file:///server/myfile.jpg
will never be loaded from an Internet web site. That's why your code doesn't work.
You have two options:
1 . If you ftplocation is a real FTP server and it can be accessed from the outer world with a real FTP URL, you can use this code:
ImageUrl='<%# String.Format(@"ftp://ftp.server.com/files/boatcompany/boats/{0}/thumbnails/{1}.{2}", Eval("BoatId"), Eval("Image.ImageId"), Eval("Image.Extension")) %>
2 . You can create a virtual subfolder in IIS inside your web project, call it Boats
and point that virtual folder to \\ftplocation\files\boatcompany\
folder. Then in your code use just this (pretty much the same code as you used before you've got the FTP):
ImageUrl='<%# String.Format(@"/Boats/{0}/thumbnails/{1}.{2}", Eval("BoatId"), Eval("Image.ImageId"), Eval("Image.Extension")) %>
Upvotes: 2