diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-05-12 16:44:17 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-05-12 16:44:17 +0300 |
| commit | 7255325ae424e0d1f1b48d01bde8357096c2db8b (patch) | |
| tree | 63d769f2cd1ee963cc06c0fd64ca142783ba612e /ExamTemplate/Services/CloudinaryService.cs | |
| parent | 3ba9108bc24f0419a552f535fbc7495071884e97 (diff) | |
| download | it-kariera-exam-template-7255325ae424e0d1f1b48d01bde8357096c2db8b.tar it-kariera-exam-template-7255325ae424e0d1f1b48d01bde8357096c2db8b.tar.gz it-kariera-exam-template-7255325ae424e0d1f1b48d01bde8357096c2db8b.zip | |
Moved services to their own folder and updated their namespaces
Diffstat (limited to 'ExamTemplate/Services/CloudinaryService.cs')
| -rw-r--r-- | ExamTemplate/Services/CloudinaryService.cs | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/ExamTemplate/Services/CloudinaryService.cs b/ExamTemplate/Services/CloudinaryService.cs deleted file mode 100644 index ef421e7..0000000 --- a/ExamTemplate/Services/CloudinaryService.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using CloudinaryDotNet; -using CloudinaryDotNet.Actions; -using Microsoft.AspNetCore.Http; -using ExamTemplate.Services.Interfaces; - -namespace ExamTemplate.Services -{ - public class CloudinaryService : ICloudinaryService - { - // Regex for getting the filename without (final) filename extension - // So, from image.png, it will match image, and from doc.my.txt will match doc.my - private static readonly Regex s_imageRegex = new(".*(?=\\.)"); - - private readonly Cloudinary _cloudinary; - - public CloudinaryService(string cloudName, string apiKey, string apiSecret) - { - this._cloudinary = new Cloudinary(new Account(cloudName, apiKey, apiSecret)); - } - - public async Task<List<string>> UploadFilesToCloud(List<IFormFile> formFiles) - { - List<string> fileUrls = new(); - foreach (var formFile in formFiles) - { - string fileName = s_imageRegex.Match(formFile.FileName).ToString(); - - using var ms = new MemoryStream(); - formFile.CopyTo(ms); - byte[] formBytes = ms.ToArray(); - - RawUploadParams rawUploadParams = new() - { - File = new FileDescription(fileName, new MemoryStream(formBytes)), - PublicId = fileName, - UseFilename = true - }; - - RawUploadResult rawUploadResult = await this._cloudinary.UploadAsync(rawUploadParams); - fileUrls.Add(rawUploadResult.Url.AbsoluteUri); - } - - return fileUrls; - } - } -} |
