当我通过PreSignedURL访问AWS S3上的文件时出现异常

时间:2018-05-16 14:54:01

标签: c# amazon-web-services amazon-s3 aws-sdk pre-signed-url

当我尝试通过PreSignedURL访问 Amazon AWS S3 上的文件时出现异常。

以下是我生成PreSignedURL的方式:

GetPreSignedUrlRequest getPreSignedUrlRequest = new GetPreSignedUrlRequest
{
    BucketName = bucketName,
    Key = fileKey,
    Verb = HttpVerb.GET,
    Expires = DateTime.Now.AddMinutes(5)
};
Uri signedUrl = new Uri(new AmazonS3Client(
    Credentials.GetCredentials(), RegionEndpoint.USEast1)
    .GetPreSignedURL(getPreSignedUrlRequest));

以下是我对Amazon Transcribe(需要Amazon S3 URL)的请求:

AmazonTranscribeServiceClient amazonTSClient =
    new AmazonTranscribeServiceClient(
        Credentials.GetCredentials(),
        RegionEndpoint.USEast1);

StartTranscriptionJobRequest transcriptionJobRequest
    = new StartTranscriptionJobRequest
    {
        TranscriptionJobName = transcriptionJobName,
        Media = new Media { MediaFileUri = signedUrl },
        MediaFormat = MediaFormat.Flac,
        LanguageCode = "en-us",
        Settings = new Settings { MaxSpeakerLabels = 2 }
    };

Task<StartTranscriptionJobResponse> transcriptionJobResponseTask
    = amazonTSClient.StartTranscriptionJobAsync(transcriptionJobRequest);
transcriptionJobResponseTask.Wait(); // A System.AggregateException is thrown here

异常详情:

  

System.AggregateException:&#39;发生了一个或多个错误。 (您提供的URI并不指向S3对象。请确保该对象存在并再次尝试您的请求。)&#39;

我尝试使用生成的URL从浏览器访问该文件,并且能够下载它。

有谁知道错误可能来自哪里?

0 个答案:

没有答案