-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44fc05b
commit 9908c48
Showing
10 changed files
with
144 additions
and
62 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"dependencies": { | ||
"storage1": { | ||
"type": "storage", | ||
"connectionId": "AzureWebJobsStorage" | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"dependencies": { | ||
"storage1": { | ||
"secretStore": null, | ||
"type": "storage.emulator", | ||
"connectionId": "AzureWebJobsStorage" | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Text; | ||
using Azure.Storage.Blobs; | ||
using Azure.Storage.Blobs.Models; | ||
|
||
namespace WebApi.Services; | ||
|
||
public class Storage | ||
{ | ||
// STARTUP | ||
public static void Startup() | ||
{ | ||
// initialize Azure services (setup storage) | ||
string awjsConnection = Environment.GetEnvironmentVariable("AzureWebJobsStorage"); | ||
|
||
// main blob container | ||
BlobContainerClient blobContainer = new(awjsConnection, "chart-demo"); | ||
blobContainer.CreateIfNotExists(); | ||
} | ||
|
||
// SAVE BLOB | ||
public static async Task<bool> PutBlob(string blobName, string csv) | ||
{ | ||
BlobClient blob = GetBlobReference(blobName); | ||
BlobHttpHeaders httpHeader = new() | ||
{ | ||
ContentType = "application/json" | ||
}; | ||
|
||
using (MemoryStream ms = new(Encoding.UTF8.GetBytes(csv))) | ||
{ | ||
ms.Position = 0; | ||
await blob.UploadAsync(ms, httpHeader); | ||
}; | ||
return true; | ||
} | ||
|
||
// HELPERS | ||
internal static BlobClient GetBlobReference(string blobName) | ||
{ | ||
BlobContainerClient blobContainer = GetContainerReference("chart-demo"); | ||
BlobClient blob = blobContainer.GetBlobClient(blobName); | ||
|
||
return blob; | ||
} | ||
|
||
private static BlobContainerClient GetContainerReference(string containerName) | ||
{ | ||
string awjsConnection = Environment.GetEnvironmentVariable("AzureWebJobsStorage"); | ||
return new BlobContainerClient(awjsConnection, containerName); | ||
} | ||
} |
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