I'm working with Webcenter Sites 12.2.1 and I have a question about templating for medias with vanity URLs. My users would like to have vanity URLs for some Medias like PDFs or Images or such blobs. I'm able to do so for text based attributes such as javascripts or css but for blob based attributes I'm a bit stuck. The point is that for doing vanity URLs for an asset I have to use a template. In the template if I have to display a text there is no problem. For a blob I can get the attribute but if I want to stream the result in as template without calling the blob server URL I don't get anything usable.
Here is the code of the template that I use:
<%@page import="java.io.InputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@ page import="com.fatwire.system.*"%>
<%@ page import="com.fatwire.assetapi.data.*"%>
<%@ page import="com.fatwire.assetapi.query.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.openmarket.xcelerate.asset.*"%>
<%@ taglib prefix="cs" uri="futuretense_cs/ftcs1_0.tld"%>
<%@ taglib prefix="ics" uri="futuretense_cs/ics.tld"%>
<%@ taglib prefix="fragment" uri="futuretense_cs/fragment.tld"%>
<%@ taglib prefix="render" uri="futuretense_cs/render.tld"%>
<%@ taglib prefix="asset" uri="futuretense_cs/asset.tld"%>
<cs:ftcs>
<%
Session ses = SessionFactory.getSession();
AssetDataManager mgr =(AssetDataManager) ses.getManager( AssetDataManager.class.getName() );
AssetId id = new AssetIdImpl( "Content_R",new Long(ics.GetVar("cid")));
List attrNames = new ArrayList();
attrNames.add( "imagefile" );
AssetData data = mgr.readAttributes( id, attrNames );
AttributeData attrDataSource = data.getAttributeData( "imagefile" );
BlobObject fileObj = (BlobObject)attrDataSource.getData();
File file = new File(fileObj.getFoldername() + fileObj.getFilename());
InputStream in = new FileInputStream(file);
byte[] bytes = new byte[2048];
int bytesRead;
ServletOutputStream out2 = response.getOutputStream();
while ((bytesRead = in.read(bytes)) != -1) {
out2.write(bytes, 0, bytesRead);
}
in.close();
%>
</cs:ftcs>
I've already tried a workaround : redirecting to the blob server but the problem is that then I can't use urls directly as for images < img src="/prettyUrl" > with a redirect doesn't work.
Did anyone try to do so ?