![](/img/trans.png)
[英]-AWS C# .Net Core- How to upload a .jpg image to S3 bucket without saving it as a file
[英]Need to implementation AWS S3 Bucket file upload using c#. Whereas file size is not limit
我需要使用c#在AWS S3存儲桶中上傳文件,其中我有一次要上傳的文件列表。 我的客戶只寄給我
(S3:arn:aws:iam :: 3 ********** 9:user / intl-livestreaming-user-prod)
上載文件后,請創建該文件的URL以從任何地方查看或通過鏈接下載它。 幫幫我,因為我第一次獲得AWS的工作我一無所知。
為了將文件上傳到Amazon S3中的存儲桶,您需要從Nuget管理器導入其AWSSDK軟件包。 完成此操作后,您可以使用這段代碼來上傳文件。 請注意,設置AmazonS3Client對象時,將需要awsAccessKeyId
, awsSecretAccessKey
和區域終端節點。 完成此操作后,您將需要將文件上傳到其中的存儲桶的名稱。 請確保存儲桶具有所需的訪問權限,以接受來自外部源的文件。
using Amazon.S3;
using Amazon;
using Amazon.S3.Transfer;
using (var client = new AmazonS3Client("awsAccessKeyId",
"awsSecretAccessKey", RegionEndpoint.{yourregionendpoint}))
{
PutObjectRequest objReq = new PutObjectRequest
{
Key = "FolderName"+"/"+"ImageOne", //If you create folder inside bucket then you use key otherwise without key also upload data successfully.
FilePath = "E:\\blah\\imageone.jpg",
BucketName = "your bucket name",
CannedACL = S3CannedACL.Private,
};
PutObjectResponse response = s3newClient.PutObject(objReq);
if (response.ETag != null)
{
string etag = response.ETag;
string versionID = response.VersionId;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.