private async Task <string> Store(string containerName, byte[] bytes, string extension, string contentType) { var container = _client.GetContainerReference(containerName); await container.CreateIfNotExistsAsync(BlobContainerPublicAccessType.Blob, null, null); var fileName = SHA256Hash.HashBytes(bytes); if (extension != null) { fileName += extension; } var blob = container.GetBlockBlobReference(fileName); if (await blob.ExistsAsync()) { _logger.LogInformation("Skipping Storing file {fileName} in container {container}, already exists", fileName, containerName); } else { _logger.LogInformation("Storing file {fileName} in container {container}", fileName, containerName); blob.Properties.ContentType = contentType; await blob.UploadFromByteArrayAsync(bytes, 0, bytes.Length); } return(_baseUrl + containerName + "/" + fileName); }
public static string Generate() { var bytes = new byte[16]; lock (Rng) Rng.GetBytes(bytes); return(SHA256Hash.HashBytes(bytes)); }