'AWS S3 public URL without Expiry date and Token
Is there any way that I can generate a Public URL without any expiry date and token? I am new in flutter and developing an application to upload the image into the AWS s3 but getting URL with token.
I'm using below code
Future<String> upload(String image,String filePath) async {
try {
print('In upload');
// Uploading the file with options
File local = File(image);
final key = filePath + DateTime.now().toString();
Map<String, String> metadata = <String, String>{};
metadata['name'] = 'filename';
metadata['desc'] = 'A test file';
S3UploadFileOptions options = S3UploadFileOptions(
accessLevel: StorageAccessLevel.guest, metadata: metadata);
UploadFileResult result = await Amplify.Storage.uploadFile(
key: key,
local: local,
options: options,
onProgress: (progress) {
print("PROGRESS: " + progress.getFractionCompleted().toString());
});
setState(() {
_uploadFileResult = result.key;
print(_uploadFileResult);
});
return await getUrl().then((value){
return value;
});
} catch (e) {
print('UploadFile Err: ' + e.toString());
}
return '';
}
for taking url
Future<String> getUrl() async {
try {
print('In getUrl');
String key = _uploadFileResult;
S3GetUrlOptions options = S3GetUrlOptions(
accessLevel: StorageAccessLevel.guest, expires: 10000);
GetUrlResult result =
await Amplify.Storage.getUrl(key: key, options: options);
setState(() {
_getUrlResult = result.url;
print(_getUrlResult);
});
return _getUrlResult;
} catch (e) {
print('GetUrl Err: ' + e.toString());
}
return '';
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
