-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileService.cs
38 lines (27 loc) · 1.35 KB
/
FileService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public async Task<List<FileUpload>> AddAws(List<IFormFile> files)
{
List<FileUpload> urls = null;
RegionEndpoint bucketRegion = RegionEndpoint.GetBySystemName(_credentials.Value.BucketRegion);
AWSCredentials myCredentials = new BasicAWSCredentials(_credentials.Value.AccessKey, _credentials.Value.Secret);
s3Client = new AmazonS3Client(myCredentials, bucketRegion);
foreach (var file in files)
{
Guid guid = Guid.NewGuid();
string fileString = file.ContentType;
string keyName = "saving_circles" + guid + "_@" + file.FileName;
using (var fileTransferUtility = new TransferUtility(s3Client))
{
using (Stream stream = file.OpenReadStream())
{
await fileTransferUtility.UploadAsync(stream, _credentials.Value.BucketName, keyName);
}
if (urls == null)
{
urls = new List<FileUpload>();
}
urls.Add(new FileUpload { Url = _credentials.Value.Domain + keyName, Name=file.FileName});
//urls.Add(file.FileName);
};
}
return urls ;
}