Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how long presigned URLs from Storage.getUrl() are valid for #2014

Open
2 of 13 tasks
gulmensedat opened this issue Aug 7, 2022 · 5 comments
Open
2 of 13 tasks
Assignees
Labels
Documentation Improvements or fixes to public documentation (docs.amplify.aws, pub.dev, readmes). feature-request A request for a new feature or an enhancement to an existing API or category. storage Issues related to the Storage Category

Comments

@gulmensedat
Copy link

Description

It works for a while without any problems, then it gives this error and doesn't shoot any images. This happens all the time in a loop. It works fine for half an hour and gives this error for half an hour.

Categories

  • Analytics
  • API (REST)
  • API (GraphQL)
  • Auth
  • Authenticator
  • DataStore
  • Storage

Steps to Reproduce

final UploadFileResult result = await Amplify.Storage.uploadFile(
          local: File(imgFile.path),
          key: '$imgPath.jpg',
          options: S3UploadFileOptions(
            metadata: metadata,
            accessLevel: StorageAccessLevel.guest,
          ));
static Future<GetUrlResult> getUrlFile(String fileKey, {S3GetUrlOptions options}) async {
    try {
      final result = await Amplify.Storage.getUrl(
        key: fileKey,
        options: options,
      );

     // print('image url: ${result.url}');
      return result;
    } on StorageException catch (e) {
      print('error down file: $e');
    }
  }

widget

FutureBuilder(
              future: AmplifyStorage.getUrlFile(urlKey,
               options: S3GetUrlOptions(
                              accessLevel: amplifyFlutter.StorageAccessLevel.guest,
                              expires: 10000))),
              builder: (context, snapshot) {
                final result = snapshot.data;
                if (result == null) {
                  return const SizedBox();
                } else {
                  return CachedNetworkImage(
                    height: 290,
                    width: double.infinity,
                    fit: BoxFit.cover,
                    imageUrl: result.url,
                    cacheKey: urlKey,
                    errorWidget: (context, url, error) {
                      return const SizedBox();
                    },
                  );
                }
              },
            )

Screenshots

error

flutter: error down file: StorageException(message: Unexpected error occurred with message: Could not retreive AWS credentials, credential value is nil or empty., recoverySuggestion: This should not happen. There is a possibility that there is a bug if this error persists. Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any existing issues that match your scenario, and file an issue with the details of the bug if there isn't. Issue encountered at:
file: /Users/sedat/Desktop/projeler/eapp/ios/Pods/Amplify/Amplify/Categories/Auth/Error/AuthError.swift
function: recoverySuggestion
line: 80, underlyingException: null)

Platforms

  • iOS
  • Android
  • Web
  • macOS
  • Windows
  • Linux

Android Device/Emulator API Level

No response

Environment

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-x64, locale tr-TR)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[!] Android Studio
    ✗ Android Studio not found at C:\Program Files\Android\Android Studio/Contents
[✓] VS Code (version 1.45.1)
[✓] VS Code (version 1.32.3)
[✓] VS Code (version 1.32.3)
[✓] Connected device (4 available)
    ! Error: Sedo is not connected. Xcode will continue when Sedo is connected. (code -13)
[✓] HTTP Host Availability

! Doctor found issues in 1 category.

Dependencies

flutter pub deps --no-dev --style=compact

Dart SDK 2.17.6
Flutter SDK 3.0.5
elimesaglikapp 1.0.0+1

dependencies:
- amplify_auth_cognito 0.6.4 [amplify_auth_cognito_android amplify_auth_cognito_ios amplify_core aws_common collection flutter meta plugin_platform_interface]
- amplify_flutter 0.6.4 [amplify_core amplify_datastore_plugin_interface amplify_flutter_android amplify_flutter_ios aws_common collection flutter meta plugin_platform_interface]
- amplify_storage_s3 0.6.4 [amplify_storage_s3_android amplify_storage_s3_ios amplify_core aws_common flutter meta plugin_platform_interface]
- cached_network_image 3.2.1 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
- cloud_firestore 3.4.0 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cupertino_icons 1.0.5
- dots_indicator 2.1.0 [flutter]
- firebase_auth 3.5.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.20.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_screenutil 5.5.3+2 [flutter]
- get 4.6.5 [flutter]
- get_it 7.2.0 [async collection]
- heic_to_jpg 0.2.0 [flutter]
- image_picker 0.8.5+3 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface]
- like_button 2.0.4 [flutter]
- path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- permission_handler 10.0.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface]
- provider 6.0.3 [collection flutter nested]
- timeago 3.2.2

transitive dependencies:
- amplify_auth_cognito_android 0.6.4 [flutter]
- amplify_auth_cognito_ios 0.6.4 [amplify_core flutter]
- amplify_core 0.6.4 [aws_common collection flutter intl json_annotation meta plugin_platform_interface uuid]
- amplify_datastore_plugin_interface 0.6.4 [amplify_core collection flutter meta]
- amplify_flutter_android 0.6.4 [flutter]
- amplify_flutter_ios 0.6.4 [amplify_core flutter]
- amplify_storage_s3_android 0.6.4 [flutter]
- amplify_storage_s3_ios 0.6.4 [flutter]
- async 2.8.2 [collection meta]
- aws_common 0.1.1 [async collection http meta stream_transform uuid]
- boolean_selector 2.1.0 [source_span string_scanner]
- cached_network_image_platform_interface 1.0.0 [flutter flutter_cache_manager]
- cached_network_image_web 1.0.1 [flutter flutter_cache_manager cached_network_image_platform_interface]
- characters 1.2.0
- charcode 1.3.1
- clock 1.1.0
- cloud_firestore_platform_interface 5.7.0 [collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 2.8.0 [cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- collection 1.16.0
- cross_file 0.3.3+1 [js meta]
- crypto 3.0.2 [typed_data]
- fake_async 1.3.0 [clock collection]
- ffi 2.0.1
- file 6.1.2 [meta path]
- firebase_auth_platform_interface 6.4.0 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 4.1.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.5.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 1.7.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- flutter_blurhash 0.7.0 [flutter]
- flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
- flutter_plugin_android_lifecycle 2.0.7 [flutter]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- http 0.13.4 [async http_parser meta path]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- image_picker_android 0.8.5+1 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 2.1.8 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_ios 0.8.5+6 [flutter image_picker_platform_interface]
- image_picker_platform_interface 2.5.0 [cross_file flutter http plugin_platform_interface]
- intl 0.17.0 [clock path]
- js 0.6.4
- json_annotation 4.6.0 [meta]
- matcher 0.12.11 [stack_trace]
- material_color_utilities 0.1.4
- meta 1.7.0
- nested 1.0.0 [flutter]
- octo_image 1.0.2 [flutter flutter_blurhash]
- path 1.8.1
- path_provider_android 2.0.16 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.10 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.6 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.4 [flutter platform plugin_platform_interface]
- path_provider_windows 2.1.0 [ffi flutter path path_provider_platform_interface win32]
- pedantic 1.11.1
- permission_handler_android 10.0.0 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.0.4 [flutter permission_handler_platform_interface]
- permission_handler_platform_interface 3.7.0 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.1.0 [flutter permission_handler_platform_interface]
- platform 3.1.0
- plugin_platform_interface 2.1.2 [meta]
- process 4.2.4 [file path platform]
- rxdart 0.27.5
- sky_engine 0.0.99
- source_span 1.8.2 [collection path term_glyph]
- sqflite 2.0.3 [flutter sqflite_common path]
- sqflite_common 2.2.1+1 [synchronized path meta]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- stream_transform 2.0.0
- string_scanner 1.1.0 [charcode source_span]
- synchronized 3.0.0+2
- term_glyph 1.2.0
- test_api 0.4.9 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.1 [collection]
- uuid 3.0.6 [crypto]
- vector_math 2.1.2
- win32 2.7.0 [ffi]
- xdg_directories 0.2.0+1 [meta path process]

Device

iPhone 12 Pro

OS

macOS 12.4

CLI Version

9.1.0

Additional Context

No response

@Jordan-Nelson Jordan-Nelson added storage Issues related to the Storage Category pending-triage This issue is in the backlog of issues to triage labels Aug 8, 2022
@fjnoyp
Copy link
Contributor

fjnoyp commented Aug 9, 2022

Thanks for your response here @dorontal

@gulmensedat can you also verify what storage access levels you've configured in your S3 bucket? When setting up with Amplify CLI did you follow the instructions listed here? => https://docs.amplify.aws/lib/storage/getting-started/q/platform/flutter/#provision-backend-storage

@fjnoyp fjnoyp added the pending-community-response Pending response from the issue opener or other community members label Aug 9, 2022
@fjnoyp fjnoyp self-assigned this Aug 9, 2022
@fjnoyp
Copy link
Contributor

fjnoyp commented Aug 19, 2022

Hi @gulmensedat any updates here?

@fjnoyp fjnoyp added the pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days. label Aug 19, 2022
@gulmensedat
Copy link
Author

gulmensedat commented Aug 19, 2022

Hi @gulmensedat any updates here?

Using Streambuilder instead of Futurebuilder, I show the link of the image with CachedNetworkImage from my database, in case of an error with errorWidget, I send a request to refresh the link using the key address. That way I don't get this error. I have a problem when I use the above with FutureBuilder. As far as I understand, it is necessary to send a request with a key and download the image link.

@Jordan-Nelson Jordan-Nelson removed pending-close-response-required The issue will be closed if details necessary to reproduce the issue are not provided within 7 days. pending-community-response Pending response from the issue opener or other community members labels Sep 19, 2022
@fjnoyp
Copy link
Contributor

fjnoyp commented Sep 19, 2022

Hi @gulmensedat thank you for the followup. The problem you encountered might not be related to Streambuilder vs. Futurebuilder but to the fact that Storage.getUrl returns a presigned url from s3 which is only valid from 0-60 minutes. Not aware that this can be configured unfortunately.

Your fix seems to be a good way forward, as making a new request will refresh the link and get a new presigned url.

@fjnoyp
Copy link
Contributor

fjnoyp commented Sep 19, 2022

We'll update the docs to make this behavior more clear. Thanks for taking the time to create this issue and share your process to resolution.

@fjnoyp fjnoyp added the Documentation Improvements or fixes to public documentation (docs.amplify.aws, pub.dev, readmes). label Sep 19, 2022
@fjnoyp fjnoyp removed the pending-triage This issue is in the backlog of issues to triage label Jan 13, 2023
@Jordan-Nelson Jordan-Nelson changed the title StorageException problem Document how long presigned URLs from Storage.getUrl() are valid for Mar 21, 2023
@Jordan-Nelson Jordan-Nelson added the feature-request A request for a new feature or an enhancement to an existing API or category. label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or fixes to public documentation (docs.amplify.aws, pub.dev, readmes). feature-request A request for a new feature or an enhancement to an existing API or category. storage Issues related to the Storage Category
Projects
None yet
Development

No branches or pull requests

3 participants