I am trying to get the preview file while using the translation integration framework.
I am using the code provided in the Bootstrap Connector (https://github.com/Adobe-Marketing-Cloud/aem-translation-framework-bootstrap-connector).
Here's the specific code parts:
(in the uploadTranslationObject() function)
// Generate Preview
if(isPreviewEnabled) {
try {
ZipInputStream zipInputStream = translationObject.getTranslationObjectPreview();
if (zipInputStream != null) {
unzipFileFromStream(zipInputStream, previewPath);
} else {
log.error("Got null for zipInputStream for " + getObjectPath(translationObject));
}
} catch (FileNotFoundException e) {
log.error(e.getLocalizedMessage(), e);
} catch (IOException e) {
log.error(e.getLocalizedMessage(), e);
}
}
log.trace("Preview Directory is: {}", previewPath);
private static void unzipFileFromStream(ZipInputStream zipInputStream, String targetPath) throws IOException {
File dirFile = new File(targetPath + File.separator);
if (!dirFile.exists()) {
dirFile.mkdirs();
log.trace("Created directory: {}",dirFile);
}
ZipEntry zipEntry = null;
while (null != (zipEntry = zipInputStream.getNextEntry())) {
String zipFileName = zipEntry.getName();
if (zipEntry.isDirectory()) {
File zipFolder = new File(targetPath + File.separator + zipFileName);
if (!zipFolder.exists()) {
zipFolder.mkdirs();
log.trace("Created directory: {}",zipFolder);
}
} else {
File file = new File(targetPath + File.separator + zipFileName);
File parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
} catch (FileNotFoundException e) {
log.error(e.getLocalizedMessage(),e);
}
int readLen = 0;
byte buffer[] = new byte[1024];
while (-1 != (readLen = zipInputStream.read(buffer))) {
fos.write(buffer, 0, readLen);
}
fos.close();
}
}
zipInputStream.close();
}
Solved! Go to Solution.
Views
Replies
Total Likes
I meant if the target path is not in the server (OS) paths like: "/mnt/crx" if you are on linux OR "c://somefolder" in windows. Is this an AEM path?
Can you check what is the value of the "targetPath" parameter? I am wondering if the file is not being generated in the server where AEM is installed and not necessarily in AEM.
I tried with a few paths, none was working. Like saving in tmp folder (/tmp/bootstrap-tms/previews/) or in var (/var/bootstrap-tms/20240119/previews). The bootstrap service has jcr:all permission on these folders.
I meant if the target path is not in the server (OS) paths like: "/mnt/crx" if you are on linux OR "c://somefolder" in windows. Is this an AEM path?
yeah I found it on a server path, thanks for pointing this out, it all works now!
Views
Replies
Total Likes
@thebestusernameifound Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies