Commit 30f18568 authored by Ashwani Pandey's avatar Ashwani Pandey
Browse files

added implementation for downloading file through file name

parent 384101a9
Pipeline #67770 failed with stages
in 34 minutes and 36 seconds
......@@ -29,12 +29,14 @@ import org.opengroup.osdu.core.ibm.objectstorage.CloudObjectStorageFactory;
import org.opengroup.osdu.file.exception.FileLocationNotFoundException;
import org.opengroup.osdu.file.exception.OsduException;
import org.opengroup.osdu.file.exception.OsduUnauthorizedException;
import org.opengroup.osdu.file.model.DownloadUrlResponse;
import org.opengroup.osdu.file.model.FileRetrievalData;
import org.opengroup.osdu.file.model.SignedUrl;
import org.opengroup.osdu.file.model.SignedUrlParameters;
import org.opengroup.osdu.file.provider.ibm.model.file.S3Location;
import org.opengroup.osdu.file.provider.ibm.model.file.TemporaryCredentials;
import org.opengroup.osdu.file.provider.interfaces.IStorageService;
import org.opengroup.osdu.file.service.FileDeliveryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -51,6 +53,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import com.ibm.cloud.objectstorage.services.s3.model.GeneratePresignedUrlRequest;
import com.ibm.cloud.objectstorage.services.s3.model.ResponseHeaderOverrides;
@Service
@Log
......@@ -94,6 +97,9 @@ public class IBMStorageServiceImpl implements IStorageService {
@Inject
private CloudObjectStorageFactory cosFactory;
@Autowired
private FileDeliveryService deliveryService;
private AmazonS3 s3Client;
......@@ -225,6 +231,10 @@ public class IBMStorageServiceImpl implements IStorageService {
GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(s3BucketName, s3ObjectKey)
.withMethod(HttpMethod.valueOf(httpMethod)).withExpiration(expiration);
ResponseHeaderOverrides responseHeaders = new ResponseHeaderOverrides();
responseHeaders.setContentDisposition("attachment; filename =\"" + signedUrlParameters.getFileName() + "\"");
generatePresignedUrlRequest.setResponseHeaders(responseHeaders);
try {
// Attempt to generate the signed S3 URL
......@@ -285,12 +295,13 @@ public class IBMStorageServiceImpl implements IStorageService {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid S3 Object Key",
"Invalid S3 Object Key - Object key cannot contain trailing '/'");
}
try {
TemporaryCredentials credentials = stsHelper.getRetrievalCredentials(fileLocation, roleArn,
this.headers.getUserEmail(), expiration);
SignedUrlParameters signedParam=new SignedUrlParameters();
SignedUrl signedUrl=createSignedUrlFileLocation(retrivaldata.getUnsignedUrl(), headers.getAuthorization(),signedParam);
DownloadUrlResponse signedUrl=deliveryService.getSignedUrlsByRecordId(retrivaldata.getRecordId(), signedParam);
retrivalDataSet.put("unsignedUrl", retrivaldata.getUnsignedUrl());
retrivalDataSet.put("signedUrl",signedUrl.getUrl().toString());
retrivalDataSet.put("signedUrl",signedUrl.getSignedUrl());
retrivalDataSet.put("signedUrlExpiration", expiration);
retrivalDataSet.put("connectionString", credentials.toConnectionString());
retrivalDataSet.put("credentials", credentials);
......@@ -302,6 +313,9 @@ public class IBMStorageServiceImpl implements IStorageService {
listOfdDataSet.add(dataset);
response.setDatasets(listOfdDataSet);
response.setProviderKey(providerKey);
}catch (Exception e) {
e.printStackTrace();
}
}
return response;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment