-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/blob #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Feat/blob #138
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3d77124
Add blob
staszkiet c450a7e
Merge branch 'feat/blob' of https://github.com/Resellio/api into feat…
staszkiet fcb5fbf
appsettings example
staszkiet c3c28c9
Working blob
staszkiet 7280a13
Merge branch 'feat/blob' of https://github.com/Resellio/api into feat…
staszkiet d005f14
Merge branch 'develop' of https://github.com/Resellio/api into feat/blob
staszkiet b71fea8
minor fixes
staszkiet 85457a0
try catch block
staszkiet 3fd5c9c
better try catch
staszkiet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
74 changes: 47 additions & 27 deletions
74
TickAPI/TickAPI.Tests/Events/Services/EventServiceTests.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,6 @@ | ||
| namespace TickAPI.Common.Blob.Abstractions; | ||
|
|
||
| public interface IBlobService | ||
| { | ||
| public Task<string> UploadToBlobContainerAsync(IFormFile image); | ||
| } |
This file contains hidden or 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,32 @@ | ||
| using Azure.Identity; | ||
| using Azure.Storage.Blobs; | ||
| using Azure.Storage.Blobs.Models; | ||
| using TickAPI.Common.Blob.Abstractions; | ||
|
|
||
| namespace TickAPI.Common.Blob.Services; | ||
|
|
||
| public class BlobService : IBlobService | ||
| { | ||
| private string _connectionString; | ||
| private string _containerName; | ||
|
|
||
| public BlobService(IConfiguration configuration) | ||
| { | ||
| _connectionString = configuration["BlobStorage:ConnectionString"]; | ||
| _containerName = configuration["BlobStorage:ContainerName"]; | ||
| } | ||
|
|
||
| public async Task<string> UploadToBlobContainerAsync(IFormFile image) | ||
| { | ||
| var container = new BlobContainerClient(_connectionString, _containerName); | ||
| Guid id = Guid.NewGuid(); | ||
| string blobName = id.ToString(); | ||
| var blob = container.GetBlobClient(blobName); | ||
| var stream = new MemoryStream(); | ||
| await image.CopyToAsync(stream); | ||
| stream.Position = 0; | ||
| var response = await blob.UploadAsync(stream); | ||
|
|
||
| return blob.Uri.ToString(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a general question here, shouldn't we do some try/catch here? I mean for example blob can be down, what then? I guess the event should be created anyway, just without image - now what happens is that the exception will be propagated to main and the event will not be created. I guess we can simply do all of this in a try block, and if anything breaks just return null