-
-
Save Pownraj-2818/4ad0f0eace4ca6e0355699b2e33c828c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<string> UploadCover(IFormFile form) | |
{ | |
BlobContainerClient blobContainerClient = new BlobContainerClient(_config.GetConnectionString("BlobStorage"), "space-cover-images"); | |
try | |
{ | |
BlobClient blobClient = blobContainerClient.GetBlobClient(form.FileName); | |
// add _copy to filename if blob already exists | |
while (blobClient.Exists()) | |
{ | |
var splitArray = blobClient.Name.Split('.'); | |
var newFileName = splitArray[0] + "_copy." + splitArray[1]; | |
blobClient = blobContainerClient.GetBlobClient(newFileName); | |
} | |
// add blob | |
using (Stream stream = form.OpenReadStream()) | |
{ | |
await blobClient.UploadAsync(stream); | |
} | |
return blobClient.Uri.ToString(); | |
} | |
catch(Exception ex) | |
{ | |
throw new Exception(ex.Message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment