Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Translation Framework: cannot get preview file

Avatar

Level 2

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);

 

 
also

 

 

	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();
	}

 

 
I've added some extra logging and it seems the specified folder was created but after checking it in CRXDE there is no such folder.
How this should work? Is there a specific folder where the preview needs to be saved?
Or is it even a working code example?

Thanks in advance!
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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?



Esteban Bustamante

View solution in original post

5 Replies

Avatar

Community Advisor

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.



Esteban Bustamante

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.

Avatar

Correct answer by
Community Advisor

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?



Esteban Bustamante

yeah I found it on a server path, thanks for pointing this out, it all works now!

Avatar

Administrator

@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.



Kautuk Sahni