Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Amazon S3 Bucket C API未捕获错误_C#_Amazon Web Services_Amazon S3 - Fatal编程技术网

C# Amazon S3 Bucket C API未捕获错误

C# Amazon S3 Bucket C API未捕获错误,c#,amazon-web-services,amazon-s3,C#,Amazon Web Services,Amazon S3,很抱歉这个可能结构不好的问题,因为这是我第一次在这里发帖 我正在使用Amazon的AWSAPI for.NET将文件保存到bucket中。通过查看其他示例和文档,我想出了下面的方法。该方法成功执行,但没有文件上载到S3存储桶。我不确定是否有任何错误,但没有办法检查,因为上传是一个无效的方法,并且没有抛出异常 我不完全确定我是否提供了正确的信息,或者是否有失败 是否有任何方法可以捕获潜在的上载错误,或监视上载进度?还是我做错了什么 public static void AddItemToS

很抱歉这个可能结构不好的问题,因为这是我第一次在这里发帖

我正在使用Amazon的AWSAPI for.NET将文件保存到bucket中。通过查看其他示例和文档,我想出了下面的方法。该方法成功执行,但没有文件上载到S3存储桶。我不确定是否有任何错误,但没有办法检查,因为上传是一个无效的方法,并且没有抛出异常

我不完全确定我是否提供了正确的信息,或者是否有失败

是否有任何方法可以捕获潜在的上载错误,或监视上载进度?还是我做错了什么

    public static void AddItemToStorage(byte[] byteArray, string itemName)
    {
        MemoryStream itemStream = new MemoryStream(byteArray);

        // sign in information
        var credentials = new Amazon.Runtime.BasicAWSCredentials(
            "APIKey",
            "APIPassword"
            );

       // Link to client
       Amazon.S3.AmazonS3Client client = new Amazon.S3.AmazonS3Client(credentials, Amazon.RegionEndpoint.EUCentral1);

        TransferUtility tu = new TransferUtility(client);

        // Actual file is stored in a GUID folder to make sure there are no collisions with file names
        string bucket = "bucket_name_here/" + Guid.NewGuid().ToString(); 
        string item = itemName.Replace(" ", "_");

        itemStream.Seek(0, SeekOrigin.Begin);
        tu.Upload(itemStream, bucket, item);

        // url would be: http://bucket_here/GUID_Folder/itemName.ext/
    }
问候,


扎克设法找到了解决办法。我需要配置为使用HTTP,将ACL设置为PublicRead,并使用上载请求来监视上载。这仍然不起作用,所以我通过请求ACL来测试文件是否上传。这使我上传的项目在存储器中可见。仍然不知道为什么,但可能会帮助其他陷入困境的人

    public static void AddItemToStorage(byte[] byteArray, string itemName)
    {
        MemoryStream itemStream = new MemoryStream(byteArray);

        var config = new AmazonS3Config();
        config.UseHttp = true;
        config.RegionEndpoint = Amazon.RegionEndpoint.EUCentral1;

        var credentials = new Amazon.Runtime.BasicAWSCredentials(
            "AWSUserKey",
            "AWSPassword"
            );

        AmazonS3Client client = new AmazonS3Client(credentials, config);
        TransferUtility tu = new TransferUtility(client);

        itemStream.Seek(0, SeekOrigin.Begin);
        TransferUtilityUploadRequest request = new TransferUtilityUploadRequest()
        {
            BucketName = "bucket_name_here" + Guid.NewGuid().ToString(),
            Key = itemName.Replace(" ", "_"),
            InputStream = itemStream,
            CannedACL = S3CannedACL.PublicRead                
        };

        request.UploadProgressEvent += Request_UploadProgressEvent;

        tu.UploadAsync(request).Wait();

        var resp = client.GetACL(new GetACLRequest()
        {
            BucketName = request.BucketName,
            Key = request.Key
        });

        itemStream.Dispose();
    }

没有这样做,但也许这个问题的答案可以帮助你:干杯,戴夫。虽然这不是一个完整的修复程序,但使用您的回答,我设法发现文件正在使用事件正确上载,因此这一定与bucket接收数据并将其添加到存储器有关