Git Product home page Git Product logo

Comments (15)

Ashish-Nanda avatar Ashish-Nanda commented on May 22, 2024

@mattRiddoch can you confirm that value.path is indeed a valid file path before passing it to the uploadFile() API?

from amplify-flutter.

mattRiddoch avatar mattRiddoch commented on May 22, 2024

@Ashish-Nanda Here is what the path looks like:
/Users/mattriddoch/Library/Developer/CoreSimulator/Devices/F694C06D-4AEA-490F-BE99-CB8635D94192/data/Containers/Data/Application/2F52DFEB-FD29-4F4E-A364-EEB065717896/tmp/image_picker_26878D92-6B72-499F-BB77-8DE1FFF011FC-52750-0000DACF01486E63.jpg
The image is coming from the library via image_picker: ^0.6.7+4 in the simulator.

from amplify-flutter.

fjnoyp avatar fjnoyp commented on May 22, 2024

Hi @mattRiddoch

I think the issue is likely coming from the image_picker library you're using. I've tried reproducing your error (using a different picker library) and have no issues uploading image files from my gallery on a iPhone SE emulator.

Could you try using the file_picker: ^1.8.0+1 in your pubspec.yaml instead to see if that works for you? We use that in our example app for picking files to upload.

from amplify-flutter.

Ashish-Nanda avatar Ashish-Nanda commented on May 22, 2024

@mattRiddoch

The path of the file you provided seems fine, so not sure why you are getting the error. I also tried a clean setup today in an attempt to reproduce your issue and can confirm upload is working as expected. We are using the file_picker library @fjnoyp mentioned above. Could you give that a try based on the code in our sample app?

Let us know if you still face issues.

from amplify-flutter.

mattRiddoch avatar mattRiddoch commented on May 22, 2024

OK! I brought in the file_picker library and am using the following uploading snippet from the example code:

void upload() async {
    try {
      print('In upload');
      // Uploading the file with options
      File local = await FilePicker.getFile(type: FileType.image);
      final key = new 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);
        print(result.key);
    } catch (e) {
      print('UploadFile Err: ' + e.toString());
    }
  }

Upon picking an asset I get the following error:
UploadFile Err: RangeError (index): Invalid value: Valid value range is empty: 0
I did set a breakpoint prior to the upload attempt and can confirm that a valid file is being passed in?

On a side note this is the exact same error I raise when I save a file to the documents folder and attempt to upload from there as well?

from amplify-flutter.

fjnoyp avatar fjnoyp commented on May 22, 2024

Hi @mattRiddoch it's strange the example code isn't working for you now as well. We've validated this code works so this issue could be related to your configuration.

Have you tried running the Amplify CLI to create a s3 bucket and performed an upload. Can you provide details on how you've generated your amplifyconfiguration.dart file?

from amplify-flutter.

Ashish-Nanda avatar Ashish-Nanda commented on May 22, 2024

@mattRiddoch can you share you amplifyconfiguration.dart file?

from amplify-flutter.

mattRiddoch avatar mattRiddoch commented on May 22, 2024

Sure thing @Ashish-Nanda

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": "<PoolId>
                            "Region": "us-east-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "<PoolId>",
                        "AppClientId": "<ClientId>",
                        "AppClientSecret": "<ClientSecret>",
                        "Region": "us-east-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH"
                    }
                },
                "PinpointAnalytics": {
                    "Default": {
                        "AppId": "<AppId>",
                        "Region": "us-east-1"
                    }
                },
                "PinpointTargeting": {
                    "Default": {
                        "Region": "us-east-1"
                    }
                },
                "S3TransferUtility": {
                    "Default": {
                        "Bucket": "<BucketId>
                        "Region": "us-east-1"
                    }
                }
            }
        }
    },
    "analytics": {
        "plugins": {
            "awsPinpointAnalyticsPlugin": {
                "pinpointAnalytics": {
                    "appId": "<AppId>",
                    "region": "us-east-1"
                },
                "pinpointTargeting": {
                    "region": "us-east-1"
                }
            }
        }
    },
    "storage": {
        "plugins": {
            "awsS3StoragePlugin": {
                "bucket": "<bucketId>",
                "region": "us-east-1",
                "defaultAccessLevel": "guest"
            }
        }
    }
}''';

from amplify-flutter.

adamcyber1 avatar adamcyber1 commented on May 22, 2024

I am having an issue identical to this one - I am configured using the example Storage application and upon uploading I also get UploadFile Err: RangeError (index): Invalid value: Valid value range is empty: 0

from amplify-flutter.

Shrey29ansh avatar Shrey29ansh commented on May 22, 2024

You can try first getting a path of the file and store that in some variable then pass that value in uploadFile function like this
image

Hope it helps!

from amplify-flutter.

mattRiddoch avatar mattRiddoch commented on May 22, 2024

@Shrey29ansh I will give this a try soon. I have gotten a little sidetracked with other features but this is still very much an issue for me. Much appreciated.

from amplify-flutter.

fjnoyp avatar fjnoyp commented on May 22, 2024

Hey @mattRiddoch have you been able to resolve this issue?

from amplify-flutter.

naoyashiga avatar naoyashiga commented on May 22, 2024

I also got this error.

RangeError (index): Invalid value: Valid value range is empty: 0.

Now I have solved this error.

The reason was that the list "plugins" in the StorageCategory class was empty.

The problem is probably in the initial configuration of the plugins.

Here is the code before the fix.

// Add Pinpoint and Cognito Plugins
AmplifyAnalyticsPinpoint analyticsPlugin = AmplifyAnalyticsPinpoint();
AmplifyAuthCognito authPlugin = AmplifyAuthCognito();
amplifyInstance.addPlugin(authPlugins: [authPlugin]);
amplifyInstance.addPlugin(analyticsPlugins: [analyticsPlugin]);

AmplifyDataStore datastorePlugin =
AmplifyDataStore(modelProvider: ModelProvider.instance);
amplifyInstance.addPlugin(dataStorePlugins: [datastorePlugin]);

// Add this line, to include the Auth plugin.
AmplifyStorageS3 storage = AmplifyStorageS3();
amplifyInstance.addPlugin(
    authPlugins: [authPlugin],
    storagePlugins: [storage]
);

// Once Plugins are added, configure Amplify
await amplifyInstance.configure(amplifyconfig);

Here is the code after the fix.

// Add Pinpoint and Cognito Plugins
AmplifyAnalyticsPinpoint analyticsPlugin = AmplifyAnalyticsPinpoint();
AmplifyAuthCognito authPlugin = AmplifyAuthCognito();

AmplifyDataStore datastorePlugin =
AmplifyDataStore(modelProvider: ModelProvider.instance);

// Add this line, to include the Auth plugin.
AmplifyStorageS3 storage = AmplifyStorageS3();
amplifyInstance.addPlugin(
    authPlugins: [authPlugin],
    analyticsPlugins: [analyticsPlugin],
    dataStorePlugins: [datastorePlugin],
    storagePlugins: [storage]
);

// Once Plugins are added, configure Amplify
await amplifyInstance.configure(amplifyconfig);

from amplify-flutter.

offlineprogrammer avatar offlineprogrammer commented on May 22, 2024

Hey @mattRiddoch . Sorry for the late reply.

I tested in iOS, and Android and I couldn't reproduce the issue

Feel free to test using the latest build and let us know if you got any issues

Thanks

from amplify-flutter.

offlineprogrammer avatar offlineprogrammer commented on May 22, 2024

Hey @mattRiddoch

I am closing this issue for now as I didn't hear from you and I couldn't reproduce as per my comment above.
We can reopen it if you are still facing the issue and when you provide details

Regards
Mo

from amplify-flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.