0
我試圖把文件上傳到使用.net SDK S3存儲,和我看到下面的錯誤響應PUTing由AWS提供的預先簽訂URL時:AWS S3 PreSignedUrl上傳出錯
你的水桶嘗試訪問必須使用指定的端點尋址
這裏是.Net代碼 - 我已經確認我的存儲桶位於USWest2。
var amazonS3Client = new AmazonS3Client(accessKey, secretKey, RegionEndpoint.USWest2);
// Generate a pre-signed URL.
string folderName = "MyFolder";
string key = "TestKey";
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest
{
BucketName = _bucketName,
Key = folderName + "/" + key,
Verb = HttpVerb.PUT,
Expires = DateTime.Now.AddMinutes(5)
};
var uri = Uri(_amazonS3Client.GetPreSignedURL(request));
// Upload a file using the pre-signed URL.
Stream stream = ... // This is set elsewhere, contains a data stream.
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
HttpWebRequest httpRequest = WebRequest.Create(uri) as HttpWebRequest;
httpRequest.Method = "PUT";
using (Stream dataStream = httpRequest.GetRequestStream())
{
byte[] buffer = new byte[8000];
int bytesRead = 0;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
dataStream.Write(buffer, 0, bytesRead);
}
}
HttpWebResponse response = httpRequest.GetResponse() as HttpWebResponse;
if(response.StatusCode != HttpStatusCode.OK)
throw new Exception("Error uploading to AWS: " + response.StatusDescription);