diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-28 19:34:06 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-03-28 19:34:06 +0300 |
| commit | 92c8160d4796c6a4cefb5770f4f4ff1e082e3f41 (patch) | |
| tree | bad8f980d7394817538e5ecd2d51ec83af144b14 /src/Services/DevHive.Services | |
| parent | 15904cb3d2ef9442b682322353c378ab321520e5 (diff) | |
| download | DevHive-92c8160d4796c6a4cefb5770f4f4ff1e082e3f41.tar DevHive-92c8160d4796c6a4cefb5770f4f4ff1e082e3f41.tar.gz DevHive-92c8160d4796c6a4cefb5770f4f4ff1e082e3f41.zip | |
Uploading files to cloudinary now uses the filename, not a guid
Diffstat (limited to 'src/Services/DevHive.Services')
| -rw-r--r-- | src/Services/DevHive.Services/Services/CloudinaryService.cs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/Services/DevHive.Services/Services/CloudinaryService.cs b/src/Services/DevHive.Services/Services/CloudinaryService.cs index 57955a2..6e2e975 100644 --- a/src/Services/DevHive.Services/Services/CloudinaryService.cs +++ b/src/Services/DevHive.Services/Services/CloudinaryService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text.RegularExpressions; using System.Threading.Tasks; using CloudinaryDotNet; using CloudinaryDotNet.Actions; @@ -11,6 +12,10 @@ namespace DevHive.Services.Services { public class CloudinaryService : ICloudService { + // 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 Regex _imageRegex = new Regex(".*(?=\\.)"); + private readonly Cloudinary _cloudinary; public CloudinaryService(string cloudName, string apiKey, string apiSecret) @@ -23,7 +28,7 @@ namespace DevHive.Services.Services List<string> fileUrls = new(); foreach (var formFile in formFiles) { - string formFileId = Guid.NewGuid().ToString(); + string fileName = _imageRegex.Match(formFile.FileName).ToString(); using (var ms = new MemoryStream()) { @@ -32,8 +37,8 @@ namespace DevHive.Services.Services RawUploadParams rawUploadParams = new() { - File = new FileDescription(formFileId, new MemoryStream(formBytes)), - PublicId = formFileId, + File = new FileDescription(fileName, new MemoryStream(formBytes)), + PublicId = fileName, UseFilename = true }; |
