You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've tried every possible combination of providing required params.
I'm trying to download a previous version of a pdf file, which exists on the server with getObject. I have checked if the version exists and its versionId in the S3 Console on s3.console.aws.amazon.com. I am also able to list the versions in the ui of the app with use of the method listObjectVersions.
In the app and on S3 I use a prefix called teamId (name is an uuid) to structure the files.
When trying to download a version of a file the code looks like this:
Future<Uint8List?> getConsentByFileIdAndVersionId({
requiredString fileId,
requiredString versionId,
requiredString teamId,
}) async {
GetObjectOutput? getObjectOutput;
/// Access to the S3 instance via the singletonfinal s3Singleton =S3Singleton();
await s3Singleton.initializeS3Client();
final accessLevel = s3Singleton.defaultAccessLevel;
final identityId = s3Singleton.identityId;
final bucket = s3Singleton.bucket;
/// These are the different attempts to get the 'key' workingfinal keyParam ="$fileId";
// final keyParam = "$teamId/$fileId";// final keyParam = "$identityId/$accessLevel/$teamId/$fileId";// final keyParam = "$accessLevel/$teamId/$fileId";log("keyParam: $keyParam", name:"StorageClient");
if (bucket !=null) {
try {
getObjectOutput =await s3Singleton.s3?.getObject(
bucket: bucket,
key: keyParam,
versionId: versionId,
);
return getObjectOutput?.body;
} onExceptioncatch (e, s) {
log("EXCEPTION in getConsentByFileIdAndVersionId",
error: e, stackTrace: s, name:"StorageClient");
returnnull;
}
}
returnnull;
}
Properties mentioned in the code above:
fileId is provided by the app, it separates files of different teams
identityId consists of the region and an id given by s3 separated by a colon.
accessLevel in the case of my app is 'private'
identityId is taken from the file's list of versions in the ui and have checked it's existence
Following the code for the s3Singleton:
classS3Singleton {
staticfinalS3Singleton _singleton =S3Singleton._internal();
S3? s3;
String? region;
String? bucket;
String? defaultAccessLevel;
String? identityId;
factoryS3Singleton() {
return _singleton;
}
S3Singleton._internal();
Future<S3?> initializeS3Client() async {
AWSCredentials? awsCredentials;
if (s3 ==null) {
awsCredentials =awaitfetchCognitoAuthSession();
finalMap<String, dynamic> amplifyConfig =jsonDecode(amplifyCofiguration.amplifyconfig);
region =
amplifyConfig["storage"]?["plugins"]["awsS3StoragePlugin"]["region"];
bucket =
amplifyConfig["storage"]?["plugins"]["awsS3StoragePlugin"]["bucket"];
/// TODO: figure out how to change the default access level on S3. /// /// Since currently the default access level is configured to 'guest' /// and I currently have no clue to change that, it will stay here /// as hard coded value.
defaultAccessLevel ='private';
// defaultAccessLevel = amplifyConfig["storage"]?["plugins"]// ["awsS3StoragePlugin"]["defaultAccessLevel"];log("region: $region");
log("awsCredentials: $awsCredentials");
if (awsCredentials !=null&& region !=null) {
log("identityId: $identityId");
final accessKey = awsCredentials.accessKeyId;
final secretKey = awsCredentials.secretAccessKey;
final expiration = awsCredentials.expiration;
final sessionToken = awsCredentials.sessionToken;
final s3Credentials =AwsClientCredentials(
accessKey: accessKey,
secretKey: secretKey,
expiration: expiration,
sessionToken: sessionToken,
);
s3 =S3(region: region!, credentials: s3Credentials);
return s3;
}
}
return s3;
}
Future<AWSCredentials?> fetchCognitoAuthSession() async {
try {
final cognitoPlugin =Amplify.Auth.getPlugin(AmplifyAuthCognito.pluginKey);
final result =await cognitoPlugin.fetchAuthSession();
identityId = result.identityIdResult.value;
finalAWSCredentials awsCredentials = result.credentialsResult.value;
return awsCredentials;
} onSessionExpiredExceptioncatch (e, s) {
log(''' SessionExpiredException in initializeS3Client, recovery: ${e.recoverySuggestion} underlyingException: ${e.underlyingException} message: ${e.message} ''', error: e, stackTrace: s, name:"StorageClient", level:400);
returnnull;
} onAuthExceptioncatch (e) {
safePrint('Error retrieving awsCredentials: ${e.message}');
returnnull;
}
}
}
Since I've spent some days to get it running, I now try it here. Maybe this is an issue of the library.
The text was updated successfully, but these errors were encountered:
I've tried every possible combination of providing required params.
I'm trying to download a previous version of a pdf file, which exists on the server with
getObject
. I have checked if the version exists and its versionId in the S3 Console on s3.console.aws.amazon.com. I am also able to list the versions in the ui of the app with use of the methodlistObjectVersions
.In the app and on S3 I use a prefix called teamId (name is an uuid) to structure the files.
When trying to download a version of a file the code looks like this:
Properties mentioned in the code above:
fileId
is provided by the app, it separates files of different teamsidentityId
consists of the region and an id given by s3 separated by a colon.accessLevel
in the case of my app is 'private'identityId
is taken from the file's list of versions in the ui and have checked it's existenceFollowing the code for the s3Singleton:
Since I've spent some days to get it running, I now try it here. Maybe this is an issue of the library.
The text was updated successfully, but these errors were encountered: