Skip to content

Commit

Permalink
Merge pull request #155 from sebagomez/patch/blob-multiple-folder
Browse files Browse the repository at this point in the history
Blobs not listed correclty when using Azurite
  • Loading branch information
sebagomez authored Jun 22, 2024
2 parents cd49bad + 168396c commit ed3d7c7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ obj/

*.user
*.suo

__azurite*.json
private*.data

.DS_Store
Expand Down
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
//"AZURE_STORAGE_CONNECTIONSTRING": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;QueueEndpoint=http://localhost:10001/devstoreaccount1;TableEndpoint=http://localhost:10002/devstoreaccount1;"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ To spin up a container with the latest version just run the following command
docker run --rm -it -p 8000:8080 sebagomez/azurestorageexplorer
```

Then open your browser and navigate to http://localhost:8000, and voilá!
Then open your browser and navigate to http://localhost:8000, et voila!

## Docker Compose

There's now a Docker Compose manifest in this repo that allows you to spin [Azurite](https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?tabs=visual-studio%2Cblob-storage) and Azure Storage web Explorer. In the manifest you can see that the `AZURE_STORAGE_CONNECTIONSTRING` environment variable is already set up to connect to Azurite; so fter spinning up the containers you can navigate to http://localhost:8080 and you should be already logged in to Azurite.
There's now a Docker Compose manifest in this repo that allows you to spin [Azurite](https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?tabs=visual-studio%2Cblob-storage) and Azure Storage web Explorer. In the manifest you can see that the `AZURE_STORAGE_CONNECTIONSTRING` environment variable is already set up to connect to Azurite; so after spinning up the containers you can navigate to http://localhost:8080 and you should be already logged in to Azurite.


```sh
docker-compose -f ./docker-compose/azurestorageexplorer.yaml up
docker-compose -f ./docker-compose/azurestorageexplorer.yaml up
```

## Kubernetes
Expand Down
7 changes: 1 addition & 6 deletions src/StorageLibrary/AzureContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public async Task<List<BlobItemWrapper>> ListBlobsAsync(string containerName, st
BlobContainerClient container = blobServiceClient.GetBlobContainerClient(containerName);

List<BlobItemWrapper> results = new List<BlobItemWrapper>();

string localPath = "/";
if (!string.IsNullOrEmpty(path))
localPath = path;

await foreach (BlobHierarchyItem blobItem in container.GetBlobsByHierarchyAsync(BlobTraits.None, BlobStates.None, "/", path, CancellationToken.None))
{
BlobItemWrapper wrapper = null;
Expand All @@ -54,7 +49,7 @@ public async Task<List<BlobItemWrapper>> ListBlobsAsync(string containerName, st
}
else if (blobItem.IsPrefix)
{
wrapper = new BlobItemWrapper($"{container.Uri}{localPath}{blobItem.Prefix}", 0);
wrapper = new BlobItemWrapper($"{container.Uri}/{blobItem.Prefix}", 0);
}

if (wrapper != null && !results.Contains(wrapper))
Expand Down
15 changes: 13 additions & 2 deletions src/StorageLibrary/Common/BlobItemWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ public class BlobItemWrapper : IEquatable<BlobItemWrapper>, IComparable<BlobItem
{
Uri m_internalUri;
public string Name { get => HttpUtility.UrlDecode(m_internalUri.Segments[m_internalUri.Segments.Length - 1]); }
public string Path { get => m_internalUri.LocalPath.Substring(Container.Length + 1, m_internalUri.LocalPath.Length - Container.Length - Name.Length - 1); }
public string Container { get => m_internalUri.Segments[1]; }
public string Path
{
get
{
int containerPos = m_internalUri.LocalPath.IndexOf(Container) + Container.Length;

return m_internalUri.LocalPath.Substring(containerPos, (m_internalUri.LocalPath.Length) - (containerPos) - Name.Length);
}
}

public string Container { get => IsAzurite ? m_internalUri.Segments[2] : m_internalUri.Segments[1]; }
public string FullName { get => $"{Path}{Name}"; }
public bool IsFile { get => !m_internalUri.Segments[m_internalUri.Segments.Length - 1].EndsWith("/"); }
public string Url
Expand All @@ -17,6 +26,8 @@ public string Url
private set { m_internalUri = new Uri(value); }
}

public bool IsAzurite { get => m_internalUri.IsLoopback; }

public long Size { get; private set; }

public decimal SizeInKBs { get => (decimal)Size / 1024; }
Expand Down
2 changes: 1 addition & 1 deletion src/web/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<AzureStorageWebExplorerVersion>2.16.1</AzureStorageWebExplorerVersion>
<AzureStorageWebExplorerVersion>2.16.2</AzureStorageWebExplorerVersion>
</PropertyGroup>
</Project>

0 comments on commit ed3d7c7

Please sign in to comment.