0

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 ?

4

1 回答 1

1

通过 Oracle 社区找到了解决方案:我必须使用控制器。

示例站点应用程序中已经给出了一个示例

http://<>:<>/sites/samples/blob_link_builder

http://docs.oracle.com/middleware/1221/wcs/develop/GUID-C8899CBC-2EC1-4A25-A887-F8B9A868084D.htm#WBCSD8200

编辑:从那以后我使用了不同的解决方案,我使用虚 URL 来处理 blob。我没有做模板,而是使用 AssetType,而是创建一个虚 URL,它将应用于我的资产的 blob 属性。这比做任何模板来显示图像或类似的东西要容易得多。

于 2016-02-11T07:34:33.903 回答