활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
Hi, I am currently implementing the Web-optimized image delivery api to convert to webp in my custom component, I researched and put into practice the documentation provided in:
The thing is that it doesn't work, I have read that for the api to work it has to be in an environment (example: dev or prod) but I have tried both locally and in environments and it doesn't work, in fact, it doesn't even show the error it is, I tried to do it with a try catch block and using java logs as adobe logs but they don't show anything.
What should I do to solve this problem?
This is my java sling model that I use, it uses 4 assets (fileReference) in this component
해결되었습니다! 솔루션으로 이동.
조회 수
답글
좋아요 수
Hi @Aaron_Dempwolff,
The method getWebOptimizedUrl will yield an empty result when calling options.get("seoname"). To address this issue, make sure to include options.put("seoname") within the getFileReference methods. You can take a look at the AssetDeliveryHelper.java file in the Core Component for guidance.
You can follow the Image Core Component's approach and use the image name as the "seoname. Here's how you can get the image name from the Asset.
// You can enhance your code with the following optimization.
public String getFileReference1() {
return getWebOptimizedUrl(request.getResourceResolver(), fileReference1);
}
.....
private String getWebOptimizedUrl(ResourceResolver resourceResolver, String path) {
Resource resource = resourceResolver.getResource(path);
Asset asset = DamUtil.resolveToAsset(resource);
String imageName = getImageNameFromAsset(asset);
final Map<String, Object> options = new HashMap<>();
options.put("preferwebp", "true");
options.put("width", "350");
options.put("height", "350");
// These 3 options are required for the AssetDelivery API to work
// Else it will return null
options.put("path", asset.getPath());
options.put("format", "webp");
options.put("seoname", imageName);
return assetDelivery.getDeliveryURL(resource, options);
}
조회 수
답글
좋아요 수
Hi @Aaron_Dempwolff,
The method getWebOptimizedUrl will yield an empty result when calling options.get("seoname"). To address this issue, make sure to include options.put("seoname") within the getFileReference methods. You can take a look at the AssetDeliveryHelper.java file in the Core Component for guidance.
You can follow the Image Core Component's approach and use the image name as the "seoname. Here's how you can get the image name from the Asset.
// You can enhance your code with the following optimization.
public String getFileReference1() {
return getWebOptimizedUrl(request.getResourceResolver(), fileReference1);
}
.....
private String getWebOptimizedUrl(ResourceResolver resourceResolver, String path) {
Resource resource = resourceResolver.getResource(path);
Asset asset = DamUtil.resolveToAsset(resource);
String imageName = getImageNameFromAsset(asset);
final Map<String, Object> options = new HashMap<>();
options.put("preferwebp", "true");
options.put("width", "350");
options.put("height", "350");
// These 3 options are required for the AssetDelivery API to work
// Else it will return null
options.put("path", asset.getPath());
options.put("format", "webp");
options.put("seoname", imageName);
return assetDelivery.getDeliveryURL(resource, options);
}
조회 수
답글
좋아요 수
I have corrected the parameters, some were not mapped well, but even correcting the parameters (path, format and seoname) still does not work, I have tried in the environments and nothing.
What can it be in this case?
조회 수
답글
좋아요 수
Hi @Aaron_Dempwolff,
It appears that the Image Src has been generated, but it hasn't been converted to the webp version.
As per Adobe Documentation:
When using the AEM SDK on localhost, the image service isn’t available, and the image rendering falls back to using the Adaptive Image Servlet. To use the web-optimized image delivery service, deploy the project to a AEMaaCS development environment to be able to test precisely how the image service behaves with the image service.
조회 수
답글
좋아요 수
That last screenshot is from dev environment, and I add a try catch block to, if the webp api fails, use the asset that the user upload.
조회 수
답글
좋아요 수
Hi @Aaron_Dempwolff,
Could you provide the AEM version, Uber-Jar version, and the exception message?
조회 수
답글
좋아요 수
In the AEM project we don't use Uber jar for cloud services projects, instead of that, we use the AEM SDK API, this is the version I use:
조회 수
답글
좋아요 수
Hi @Aaron_Dempwolff, Try this to initialize AssetDelivery.
import com.adobe.cq.wcm.spi.AssetDelivery;
...
@OSGiService(injectionStrategy = InjectionStrategy.OPTIONAL)
private AssetDelivery assetDelivery;
조회 수
답글
좋아요 수