我正在使用C#AWS开发工具包(版本3.3.107.4)将pdf文件上传到S3存储桶。它在s3上创建了一个0字节的空文件。 而本地文件具有适当的预期长度。 你能帮我吗? API调用的结果始终为200。下面是我的代码:
public bool sendMyFileToS3(System.IO.Stream localFilePath, string bucketName, string subDirectoryInBucket, string fileNameInS3)
{
IAmazonS3 client = new AmazonS3Client(RegionEndpoint.USEast1);
TransferUtility utility = new TransferUtility(client);
TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
if (subDirectoryInBucket == "" || subDirectoryInBucket == null)
{
request.BucketName = bucketName; //no subdirectory just bucket name
}
else
{
// subdirectory and bucket name
request.BucketName = bucketName + @"/" + subDirectoryInBucket;
}
request.Key = fileNameInS3; //file name up in S3
request.InputStream = localFilePath;
request.ContentType = "";
utility.Upload(request); //commensing the transfer
return true; //indicate that the file was sent
}