refactor: add prefix support for storage column configuration and update blob path generation
This commit is contained in:
@@ -4,10 +4,13 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
|
||||
"git.ksdemosapps.com/kylesoda/go-migrate/internal/app/config"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
|
||||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -72,16 +75,15 @@ func (c *Client) UploadAndGetURL(ctx context.Context, blobPath string, buffer []
|
||||
return "", ErrInvalidInput
|
||||
}
|
||||
|
||||
fullPath := blobPath
|
||||
if c.azureStorageConfig.Prefix != "" {
|
||||
fullPath, _ = url.JoinPath(c.azureStorageConfig.Prefix, blobPath)
|
||||
fullPath := path.Join(c.azureStorageConfig.Prefix, blobPath)
|
||||
|
||||
contentType := http.DetectContentType(buffer)
|
||||
opts := &azblob.UploadBufferOptions{
|
||||
HTTPHeaders: &blob.HTTPHeaders{BlobContentType: &contentType},
|
||||
}
|
||||
if _, err := c.client.UploadBuffer(ctx, c.azureStorageConfig.Container, fullPath, buffer, opts); err != nil {
|
||||
return "", fmt.Errorf("uploading blob %s: %w", fullPath, err)
|
||||
}
|
||||
|
||||
if err := c.UploadBuffer(ctx, c.azureStorageConfig.Container, fullPath, buffer); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
blobEndpoint, _ := url.JoinPath(c.azureStorageConfig.ServiceURL, c.azureStorageConfig.AccountName)
|
||||
blobURL, _ := url.JoinPath(blobEndpoint, c.azureStorageConfig.Container, fullPath)
|
||||
return blobURL, nil
|
||||
return fullPath, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user