【发布时间】:2014-08-22 15:06:13
【问题描述】:
我向question 询问了如何访问上传的资产,将其发送到第三方服务,然后将资产替换为从第三方服务发回的资产。
我得到了一个很好的answer 来回答这个问题,使用它我可以编写下面的代码,当我上传单个资产时效果很好,但是,当我上传多个资产时它不起作用同时资产。当我同时上传多个资产时,资产名称和内容不是上传的内容。例如,如果我上传1.jpg 2.jpg 3.jpg 4.jpg 5.jpg,那么它会随机将1.jpg 的内容替换为2.jpg,或者将4.jpg 的内容替换为3.jpg 等。
public void execute(WorkItem item, WorkflowSession wfsession,MetaDataMap args) throws WorkflowException {
try
{
final Map<String, Object> map = new HashMap<String, Object>();
map.put( "user.jcr.session", wfsession.getSession());
ResourceResolver rr = resolverFactory.getResourceResolver(map);
String path = item.getWorkflowData().getPayload().toString();
Resource resource = rr.getResource(path);
InputStream is = resource.adaptTo(InputStream.class);
Rendition rendition = resource.adaptTo(Rendition.class);
Asset asset = rendition.getAsset();
//send the asset to service and get newInputStream from the service
InputStream newInputStream = myService.sendFile(is);
//replace the original rendition with the one received from the service
asset.addRendition(rendition.getName(),newInputStream,asset.getMimeType());
}
catch (Exception e) {...}
}
问题
- 我想知道是否有一种方法可以更改我的代码来处理同时上传多个资产的用例。我相信这种情况正在发生,因为在 CQ5 发送新资产之前,我的服务返回输入流的响应可能尚未完成。有没有办法阻止这种情况,以便我的处理步骤一次只处理一张图像?
注意:
- 我为我的
Process Step选中了Handler Advance选项 - 根据我的测试:如果我同时上传两个资产,一切正常...除此之外的任何东西都会导致问题。
【问题讨论】: