简体   繁体   中英

Unable to upload image to Amazon s3 from Windows Phone using .NET SDK for Amazon

I am using .NET SDK for Amazon S3 in my Windows Phone 8 project. I am using the following code,

public  async void UploadFile(string bucketName, string filepath)
    {
        string awsID = "myID";
        string secretKey = "mysecretkey";

        AmazonS3Client s3Client = new AmazonS3Client(awsID, secretKey);
        var request = new PutObjectRequest()
        {
            BucketName = "bucketname",
             InputStream = App.GetResourceStream(new Uri("projectname;component/Assets/call.png", UriKind.Relative)).Stream
        };

        await s3Client.PutObjectAsync(request);
        Console.WriteLine("File Uploaded");

    }

I have set the content type of image as "Resource" I am getting this error

XML is malformed from amazon s3.

On googling i found a link s3-put fails to send file asking me to append filename with name of the bucket.On doing so,I know get a folder created inside my bucket int he name of file and my contents are not uploaded.

For WinRT and Windows Phone FilePath property must be in the form of "ms-appdata:///local/file.txt" as mentioned here .

To upload from isolated storage you can use InputStream property.

var request = new PutObjectRequest()
    {
        BucketName = "bucketname",
        InputStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile("YOUR_FILE_PATH", FileMode.Open);
    };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM