Closed emuhaxheri closed 1 year ago
Looking at the generated url (shown in your screenshot), it doesn't seem to be a correct url at all.
Can you share the code snippet of how you are invoking the getUrl
API and parameters?
In addition, have you configured Storage category using Amplify CLI, or are you trying to use the Storage category with your existing S3 resource?
Are you trying to use Storage plugin with CloudFront proxied S3 bucket? (this is not currently supported.)
Hello! @HuiSF!! below you will find my code snippets and my answers to your questions.
No I haven't configured the storage category using Amplify CLI because I'm importing the storage package from an existing web app and as per the Storage plugin being with CloudFront proxied S3 bucket the answer is yes, I'm using that.
How should I proceed with this?
// Getting the url from the package
Future<GetUrlResult> getImageUrlFromS3(String fileKey) async {
try {
final result = await Amplify.Storage.getUrl(
key: fileKey,
);
// print('image url: ${result.url}');
return result;
} on StorageException catch (e) {
print('error down file: $e');
throw errorSnackBar('Oopss', e.toString());
}
}
// Implementing the function in the UI as a FutureBuilder
child: FutureBuilder<GetUrlResult>(
future: projectDetailsController
.getImageUrlFromS3(
task!.files![index].path!,
),
builder: (context, snapshot) {
final result = snapshot.data;
print(result);
if (result == null) {
return const SizedBox();
} else {
return Container(
width: 300,
height: 300,
decoration: BoxDecoration(
image: DecorationImage(
image:
CachedNetworkImageProvider(
result.url,
),
fit: BoxFit.fill,
),
),
);
}
},
),
// What we get from "task!.files![index].path!"
https://db9ua1jy8sh8i.cloudfront.net/16a0cdaf-747e-4bc9-b848-e656aa766500/4689ad3e-1b7b-4504-9520-43539fdd9d35.jpeg
Thanks for the follow up @emuhaxheri It sounds like that you have a s3 bucket, that hosts some images files, your Web App renders the images from it via CloudFront. And you are trying to do the same thing for your Flutter built mobile App, is that correct? Unfortunately the Storage S3 plugin doesn't work with CloudFront, it requires direct interaction with the S3 bucket itself.
All Amplify Storage S3 plugin APIs requires object key that identifies the "location" of the object in your bucket. In your code example you are trying to getUrl
with a CloudFront url, that won't work.
Can you look up what's the actual object key in your bucket that below url points to?
https://db9ua1jy8sh8i.cloudfront.net/16a0cdaf-747e-4bc9-b848-e656aa766500/4689ad3e-1b7b-4504-9520-43539fdd9d35.jpeg
There may be a workaround for your use case.
Hello @HuiSF I'm a colleague of @emuhaxheri and I've taken over this task,
I've been looking for the object key for the files and I can't seem to determine what it actually is but I can suspect that it is the fileName which would be this "4689ad3e-1b7b-4504-9520-43539fdd9d35.jpeg", as a workaround I've been thinking of constructing the url myself by have the provided url as the starting point then add the signature and the token on it, would that work? or do you have any cleaner other workarounds in mind? If so please do tell, cuz I would prefer doing that then doing what I suggested :)
A question that I would like to ask is that does what you said correspond with uploading a file as well, or is it just for "getUrl()" function?
I'm importing the storage package from an existing web app
How are you getting the URL to display these in the web app? Are you using Amplify?
Hi @akotorri @emuhaxheri I'm sorry that I lost track of this thread.
but I can suspect that it is the fileName which would be this "4689ad3e-1b7b-4504-9520-43539fdd9d35.jpeg"
You meant you cannot view the bucket at all to identity the object key that you were trying to getUrl
with?
as a workaround I've been thinking of constructing the url myself by have the provided url as the starting point then add the signature and the token on it, would that work?
Still, were you trying to use a pre-existing s3 bucket with Amplify Storage? I'm not sure how to answer your question precisely with the information I gathered so far.
I would like to ask is that does what you said correspond with uploading a file as well, or is it just for "getUrl()" function?
Yes that's correct, Amplify Storage S3 plugin has a set of predefined auth rules associated with file access level as well, if you were trying to use pre-existing s3 bucket without conforming the auth set up, you may need extra steps to make it work.
Please let me know.
@akotorri @emuhaxheri - If you are still facing this issue please take a look at @HuiSF's questions above.
I am having the same issue, can someone help?
I am getting this issue in android actually i have uploaded a image from ios in android dit is not getting .
Description
We are trying to show s3 file/images on mobile app. We integrated the google and email auth from which we got the session and also its token and when we try to open a raw URL of the file/image it says access denied 403. When we try to do it with "Amplify.Storage.getUrl(imageUrl)" it still returns access denied 403.
How should I display an image from s3 bucket?
Categories
Steps to Reproduce
Screenshots
Platforms
Android Device/Emulator API Level
No response
Environment
Dependencies
Device
Iphone 14 pro max (simulator)
OS
iOS 16.0
Deployment Method
Amplify CLI
CLI Version
10.0.0
Additional Context
No response
Amplify Config
const amplifyconfig = ''' { "UserAgent": "aws-amplify-cli/2.0", "Version": "1.0", "auth": { "plugins": { "awsCognitoAuthPlugin": { "UserAgent": "aws-amplify-cli/0.1.0", "Version": "0.1.0", "IdentityManager": { "Default": {} }, "CredentialsProvider": { "CognitoIdentity": { "Default": { "PoolId": "------", "Region": "us-east-1" } } }, "CognitoUserPool": { "Default": { "PoolId": "------", "AppClientId": "------", "Region": "us-east-1" } }, "Auth": { "Default": { "OAuth": { "WebDomain": "------", "AppClientId": "------", "SignInRedirectURI": "------", "SignOutRedirectURI": "------", "Scopes": [ "aws.cognito.signin.user.admin", "email", "openid", "profile" ] }, "authenticationFlowType": "CUSTOM_AUTH", "socialProviders": [ "GOOGLE" ], "usernameAttributes": [ "EMAIL" ], "signupAttributes": [ "NAME", "EMAIL" ], "passwordProtectionSettings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [] }, "mfaConfiguration": "OFF", "mfaTypes": [], "verificationMechanisms": [] } }, "S3TransferUtility": { "Default": { "Bucket": "------", "Region": "us-east-2" } } } } }, "storage": { "plugins": { "awsS3StoragePlugin": { "bucket": "------", "region": "us-east-2", "defaultAccessLevel": "guest" } } } }''';