I've some image file in my Local Network and I want to display them in the DataTable in JSF. I'm using JSF2.0 and Tomahawk 1.1.13. Below is the JSF code.
<t:dataTable newspaperColumns="3" value="#{startupBean.colorList}" newspaperOrientation="horizontal" var="colorBO">
<f:facet name="spacer">
<f:verbatim></f:verbatim>
</f:facet>
<h:column>
<h:graphicImage id="colors" alt="jsf-sun" url="#{colorBO.color_url}">
</h:graphicImage>
</h:column>
</t:dataTable>
I'm giving the path of the file as "\\root\sub\sub\xxx.jpg" in my backing bean. But when the JSF page renders, it displays a default icon. When I right click on the icon and check the properties, the below is what I get.
http://localhost:8080/projname//root/sub/sub/xxx.jpg
I tries using both backslash and forward slash in the path name. No change in the output though. I dont' know how the http part gets into the file path. I'm missing something for sure.
You're making a conceptual mistake here. It's the webbrowser who has to download the image separately by a valid and reachable URL once it encounters a <img> element, it's not the webserver who has to somehow magically embed the image from the local disk file system within the HTML page which is returned to the webbrowser.
You need to make the image available by a valid and reachable URL, so that the webbrowser can download it. A local disk file system path is surely not a valid and reachable URL. Even more, it would be a huge security hole if a server machine's local disk file system contents was automagically fully exposed into the world wide web.
One of the simplest ways of solving this problem is just placing the image in the public webcontent (there where your JSF files also are), so that it's available in the web.
Another way is to configure the server to publish the folder into the web so that it's available by a specific URL as well. It's unclear which server you're using, so here's just a Tomcat example:
<Context docBase="/root/sub/sub" path="/images" />
This way the image is available by http://localhost:8080/images/xxx.jpg and then this <h:graphicImage> approach should work:
<h:graphicImage src="/images/xxx.jpg" />
See also:
Load images from outside of webapps / webcontext / deploy folder using <h:graphicImage> or <img> tag
Simplest way to serve static data from outside the application server in a Java web application
Related
I have an asp.net 4.0 webforms website with a CSS stylesheet which I've embedded into a separate assembly.
If I load the css using ClientScript.GetWebResourceUrl it loads, but does it with that /WebResource.axd?whateverlongstringofstuff
I was hoping that I could use a Virtual Path provider so that i can simply reference it by linking to say ~/Custom/my.css
where ~/Custom/* would go through the VPP and serve it from the embedded resource.
the reason I was doing this is I want users to be able to easily override my css by adding the actual css file in that location so it serves that one instead.
However, no matter what I try, I get a 404 on that resource url, even though in my custom ResourceResolver, the fileExists resolves to true (because it does find it in the resources assembly).
So I suspect this is because IIS is configured to serve static files (css, jpg, png, etc) directly, bypassing anything I could add to the pipeline, and the only way around this would be to have my users change their web.config or IIS settings.
Is this true? because if it is I'll abandon this and go back to the WebResource.axd, but it would really be nice if this could be done
Here's what I would like to accomplish:
I have a file stored in Windows Azure Blob Storage (or for that matter any file which is not on my web server but accessible via a URL).
I want to force download a file without actually downloading the file on my web server first i.e. browser should automatically fetch the file from this external URL and prompts the user to download it.
Possible Solutions Explored:
Here's what I have explored so far (and why they won't work):
Using something like FileContentResult as described here Returning a file to View/Download in ASP.NET MVC to download the file. This solution would require me to fetch the contents on my server and then stream from my server to the browser. For this reason this solution won't work.
Using HTML 5 download attribute: HTML 5 download attribute would have worked perfectly fine however the problem is that while it is really a very neat solution, it is not supported in all browsers.
Changing the file's content type: Another thing I could do (at least for the files that I own) to change the content type property of the file to something that the browser wouldn't understand and thus would be forced to download the file. This might work in some browsers however not in all as IE is smart enough to go beyond the content type and sees the file's content to determine the content type. Furthermore if I don't own the files, then I won't have access to changing the content type of the file.
Simply put, in my controller action I should be able to specify the URL of the file and somehow browser should force download the file.
Is this something which can be accomplished? If yes, then any ideas how I could accomplish this?
Simply put, in my controller action I should be able to specify the URL of the file and somehow browser should force download the file [without exposing the URL of the file to the client].
You can't. If the final URL is to remain hidden, your server must serve the data, so your server must download the file from the URL.
Your client can't download a file it can't get the URL to.
You can create file transfer WCF service (REST) which will stream your content from blob storage or from other sources through your file managers to client browser directly by URL.
https://{service}/FileTransfer/DownloadFile/{id, synonym, filename etc}
Blob path won't be exposed, web application will be free from file transfer issues.
I'm working on an ASP.NET web application for our corporate intranet users. I have a form where a user should provide a path to the file on the local network (something like "\localServer\someFolder\someFile.ext") without uploading the actual file. The issue is that users don't want to type the whole file path and want to use some kind of visual browse dialog.
The standard HTML <input type=file> element allows to browse for a file, but most of the browsers (except for IE) don't allow to access file's full path, so I think it should be done by some external component like Silverlight, Flash, Java applet etc.
I tried to do it with Silverlight, but I'm getting a SecurityException when trying to access file's full path using Silverlight's OpenFileDialog class.
This java applet http://jumploader.com/demo_images.html seems to do something similar to what I'm looking for, but it's focused on uploading files - I only need to be able to get file's full path and pass it to the server as a string.
Any suggestions would be appreciated.
Telerik ASP.NET AJAX RadFileExplorer has the functionality you're looking for:
http://www.telerik.com/products/aspnet-ajax/fileexplorer.aspx
You can use their Custom File Content Provider to hook the GUI to your server's file system.
http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/server-sideapi/dbfilebrowsercontentprovider/defaultcs.aspx
This should be possible with Flash's uploading capabilities. SWFUpload has an API that you may be able to access from JavaScript to extract the selected file name without actually uploading anything. See docs here, for example getFile():
getFile is used to retrieve a File Object from the queue. The file retrieved by passing in a file id (the id property from a file object) or a file index (the index property from a file object).
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:
the files are not named with a tiff extension (does it matter?)
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?
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).
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.
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.
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.
My problem: I have a program in Flex3 that accesses a server. The program itself is on a server and accessed through a web browser. The point is that I don't want to hardcode in the swf file the IP of the server to access, since it changes and for various other reasons...
How can I do that? Can I put a file in the same directory and what then?
To access a config file on the same server as the SWF, you should be able to use an HTTPService or URLLoader with a relative URL rather than absolute. You can get fancier (changing ports) by accessing the url field of your base Application and creating a new absolute URL from that.
If the SWF is hosted separately from the HTML, you can use BrowserManager url to build your config url instead.
See this article: Externalizing Service Configuration using BlazeDS and LCDS
It will also work for HTTPService with some minor modifications.