amazon-archives / aws-sdk-xamarin

AWS Mobile SDK for Xamarin (Beta)
Apache License 2.0
45 stars 18 forks source link

Unable to upload image to S3 with xamarin AWS S3 SDK #11

Closed plvugteveen closed 9 years ago

plvugteveen commented 10 years ago

I’m trying to upload an image to AWS S3 service, but it doesn’t seem to be working.

I simplified the project down to the bare minimum. Here's the code. Error is below too Am I doing something wrong? (I removed my access keys from the code, but used real ones when testing)

Thanks for any help

    partial void UploadButton_TouchUpInside (UIButton sender)
    {
        try 
        {
            string awsAccessKeyID = "[my access key]";
            string awsSecretAccessKey = "[my secret access key]";

            AmazonS3Config config = new AmazonS3Config();
            config.ServiceURL = "s3.amazonaws.com";
            config.UseHttp = true;

            AmazonS3Client client = new AmazonS3Client( awsAccessKeyID,
                awsSecretAccessKey,config);

            TransferUtility transferUtility = new TransferUtility (client);

            TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
            request.BucketName = "fittiv-users-pictures";
            request.FilePath = "Post5.jpg";

            //Test that the path is correct
            UIImage image = UIImage.FromFile("Post5.jpg");

            System.Threading.CancellationToken canellationToken = new System.Threading.CancellationToken();

            transferUtility.UploadAsync(request,canellationToken);

        } catch (Exception ex){
            Console.WriteLine (ex.ToString ());
        }
    }

System.NullReferenceException: Object reference not set to an instance of an object at Amazon.S3.Transfer..get_ContentLength () [0x00000] in /Users/parry/Projects/aws-sdk-xamarin-master/AWS.XamarinSDK/AWSSDK_Core/Amazon.S3/Transfer/TransferUtilityUploadRequest.cs:404 at Amazon.S3.Transfer.TransferUtility.IsMultipartUpload (Amazon.S3.Transfer.TransferUtilityUploadRequest request) [0x00000] in /Users/parry/Projects/aws-sdk-xamarin-master/AWS.XamarinSDK/AWSSDK_Core/Amazon.S3/Transfer/TransferUtility.cs:329 at Amazon.S3.Transfer.TransferUtility.GetUploadCommand (Amazon.S3.Transfer.TransferUtilityUploadRequest request, System.Threading.SemaphoreSlim asyncThrottler) [0x00006] in /Users/parry/Projects/aws-sdk-xamarin-master/AWS.XamarinSDK/AWSSDK_Core/Amazon.S3/Transfer/TransferUtility.async.cs:282 at Amazon.S3.Transfer.TransferUtility.UploadAsync (Amazon.S3.Transfer.TransferUtilityUploadRequest request, CancellationToken cancellationToken) [0x00000] in /Users/parry/Projects/aws-sdk-xamarin-master/AWS.XamarinSDK/AWSSDK_Core/Amazon.S3/Transfer/TransferUtility.async.cs:184 at TestAWSS3iOS.TestAWSS3iOSViewController.UploadButton_TouchUpInside (MonoTouch.UIKit.UIButton sender) [0x00064] in /Users/parry/Projects/TestAWSS3/TestAWSS3iOS/TestAWSS3iOSViewController.cs:82

tawalke commented 10 years ago

I will have to test this fully to see your issue, but at first glance it does not seem as if you called the async function UploadAsync properly either by using Async/Await or an async lambda function.

I’ll run the code and provide some feedback on the error.

Sent from Windows Mail

From: plvugteveen Sent: ‎Tuesday‎, ‎November‎ ‎25‎, ‎2014 ‎7‎:‎01‎ ‎PM To: 'awslabs/aws-sdk-xamarin'

I’m trying to upload an image to AWS S3 service, but it doesn’t seem to be working.

I simplified the project down to the bare minimum. Here's the code. Error is below too Am I doing something wrong? (I removed my access keys from the code, but used real ones when testing)

Thanks for any help partial void UploadButton_TouchUpInside (UIButton sender) { try { string awsAccessKeyID = "[my access key]"; string awsSecretAccessKey = "[my secret access key]";

        AmazonS3Config config = new AmazonS3Config();
        config.ServiceURL = "s3.amazonaws.com";
        config.UseHttp = true;

        AmazonS3Client client = new AmazonS3Client( awsAccessKeyID,
            awsSecretAccessKey,config);

        TransferUtility transferUtility = new TransferUtility (client);

        TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
        request.BucketName = "fittiv-users-pictures";
        request.FilePath = "Post5.jpg";

        //Test that the path is correct
        UIImage image = UIImage.FromFile("Post5.jpg");

        System.Threading.CancellationToken canellationToken = new System.Threading.CancellationToken();

        transferUtility.UploadAsync(request,canellationToken);

    } catch (Exception ex){
        Console.WriteLine (ex.ToString ());
    }
}

System.NullReferenceException: Object reference not set to an instance of an object at Amazon.S3.Transfer..get_ContentLength () [0x00000] in /Users/parry/Projects/aws-sdk-xamarin-master/AWS.XamarinSDK/AWSSDK_Core/Amazon.S3/Transfer/TransferUtilityUploadRequest.cs:404 at Amazon.S3.Transfer.TransferUtility.IsMultipartUpload (Amazon.S3.Transfer.TransferUtilityUploadRequest request) [0x00000] in /Users/parry/Projects/aws-sdk-xamarin-master/AWS.XamarinSDK/AWSSDK_Core/Amazon.S3/Transfer/TransferUtility.cs:329 at Amazon.S3.Transfer.TransferUtility.GetUploadCommand (Amazon.S3.Transfer.TransferUtilityUploadRequest request, System.Threading.SemaphoreSlim asyncThrottler) [0x00006] in /Users/parry/Projects/aws-sdk-xamarin-master/AWS.XamarinSDK/AWSSDK_Core/Amazon.S3/Transfer/TransferUtility.async.cs:282 at Amazon.S3.Transfer.TransferUtility.UploadAsync (Amazon.S3.Transfer.TransferUtilityUploadRequest request, CancellationToken cancellationToken) [0x00000] in /Users/parry/Projects/aws-sdk-xamarin-master/AWS.XamarinSDK/AWSSDK_Core/Amazon.S3/Transfer/TransferUtility.async.cs:184 at TestAWSS3iOS.TestAWSS3iOSViewController.UploadButton_TouchUpInside (MonoTouch.UIKit.UIButton sender) [0x00064] in /Users/parry/Projects/TestAWSS3/TestAWSS3iOS/TestAWSS3iOSViewController.cs:82

— Reply to this email directly or view it on GitHub.

plvugteveen commented 10 years ago

Thanks. Do you have an example of how to call it?

santiagohernandez commented 10 years ago

im very new with this but i uploaded a file, using this:

                AmazonS3Config config = new AmazonS3Config();
                config.ServiceURL = "s3.amazonaws.com";
                config.UseHttp = true;
                config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;

look at the final line, try it

tawalke commented 9 years ago

@santiagohernandez is correct that the RegionEndpoint is now required when calling any service. @plvugteveen Did you try your code ensuring the endpoint is explicitly noted? Does it work when you include this?

tawalke commented 9 years ago

@plvugteveen @santiagohernandez I didn't respond earlier but did you try the new SDK that was created on Jan. 23rd. It should fix these issues.

tawalke commented 9 years ago

Can you show your code. You should be able to just set RegionEndpoint.USEast1

Thanks,

TEW

Sent from Windows Mail

From: Scott Weeden Sent: ‎Thursday‎, ‎March‎ ‎5‎, ‎2015 ‎2‎:‎06‎ ‎AM To: 'awslabs/aws-sdk-xamarin' Cc: Tara Walker

Might be a little late, but there is no us-east s3 configuration. But I'm new to this too s3.amazonaws.com s3.eu-central-1.amazonaws.com s3.cn-north-1.amazonaws.com.cn

— Reply to this email directly or view it on GitHub.