How to use generatePreSignedURLIfExists method of com.testsigma.service.OnPremiseStorageService class

Best Testsigma code snippet using com.testsigma.service.OnPremiseStorageService.generatePreSignedURLIfExists

Source:OnPremiseStorageService.java Github

copy

Full Screen

...107 }108 return preSignedURL;109 }110 @Override111 public Optional<URL> generatePreSignedURLIfExists(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel, Integer expiryTimeInMinutes) {112 log.debug("Generating File URL if exists:" + relativeFilePathFromBase);113 Optional<URL> returnURL = Optional.empty();114 String rootDirectory = getRootDirectory();115 if (rootDirectory.contains("\\") || rootDirectory.contains("\\\\") ){116 String lastChar = String.valueOf(rootDirectory.charAt(rootDirectory.length() - 1));117 relativeFilePathFromBase = lastChar.equals("\\") || lastChar.equals("\\\\") ?118 relativeFilePathFromBase.replaceAll("/", "\\\\").substring(1) :119 relativeFilePathFromBase.replaceAll("/", "\\\\");120 }121 File file = Paths.get(rootDirectory, relativeFilePathFromBase).toFile();122 if (file.exists()) {123 log.debug("File exists, generating pre-signed URL for:" + relativeFilePathFromBase);124 returnURL = Optional.ofNullable(generatePreSignedURL(relativeFilePathFromBase, storageAccessLevel, expiryTimeInMinutes));125 }126 return returnURL;127 }128 @Override129 public Optional<URL> generatePreSignedURLIfExists(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) {130 return generatePreSignedURLIfExists(relativeFilePathFromBase, storageAccessLevel, 600);131 }132 @Override133 public URL generatePreSignedURL(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) {134 return generatePreSignedURL(relativeFilePathFromBase, storageAccessLevel, 600);135 }136 @Override137 public String downloadToLocal(String relativeFilePathFromBase, StorageAccessLevel storageAccessLevel) throws TestsigmaException {138 return getRootDirectory() + File.separator + relativeFilePathFromBase;139 }140 @Override141 public void deleteFile(String filePath) {142 FileUtils.deleteQuietly(new File(filePath));143 }144 @Override...

Full Screen

Full Screen

generatePreSignedURLIfExists

Using AI Code Generation

copy

Full Screen

1public class OnPremiseStorageService {2 private static final Logger logger = LoggerFactory.getLogger(OnPremiseStorageService.class);3 public String generatePreSignedURLIfExists(String bucketName, String keyName) {4 String preSignedURL = null;5 try {6 AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build();7 boolean exists = s3Client.doesObjectExist(bucketName, keyName);8 if (exists) {9 GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, keyName);10 generatePresignedUrlRequest.setExpiration(new Date(System.currentTimeMillis() + 3600000));11 preSignedURL = s3Client.generatePresignedUrl(generatePresignedUrlRequest).toString();12 }13 } catch (Exception e) {14 logger.error("Error while generating pre-signed URL for key: " + keyName + " in bucket: " + bucketName

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testsigma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful