feat(azure_blob): update content-type and md5

pull/8409/head
New Future 2025-04-19 19:30:44 +00:00
parent 41bdab49aa
commit 01104e55b1
1 changed files with 26 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package azure_blob
import ( import (
"context" "context"
"encoding/base64"
"fmt" "fmt"
"io" "io"
"path" "path"
@ -12,11 +13,15 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore" "github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/sas" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/sas"
"github.com/alist-org/alist/v3/internal/driver" "github.com/alist-org/alist/v3/internal/driver"
"github.com/alist-org/alist/v3/internal/model" "github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/utils"
log "github.com/sirupsen/logrus"
) )
// Azure Blob Storage based on the blob APIs // Azure Blob Storage based on the blob APIs
// Link: https://learn.microsoft.com/rest/api/storageservices/blob-service-rest-api // Link: https://learn.microsoft.com/rest/api/storageservices/blob-service-rest-api
type AzureBlob struct { type AzureBlob struct {
@ -279,6 +284,27 @@ func (d *AzureBlob) Put(ctx context.Context, dstDir model.Obj, stream model.File
// Determine optimal upload options based on file size // Determine optimal upload options based on file size
options := optimizedUploadOptions(stream.GetSize()) options := optimizedUploadOptions(stream.GetSize())
// Set metadata and content type
contentType := stream.GetMimetype()
if contentType == "" {
contentType = "application/octet-stream" // Default content type
}
options.HTTPHeaders = &blob.HTTPHeaders{
BlobContentType: &contentType,
}
// Set content MD5 hash if available
base64MD5 := stream.GetHash().GetHash(utils.MD5)
if base64MD5 != "" {
// covert base64 to hex byte
md5, err := base64.StdEncoding.DecodeString(base64MD5)
if err == nil && len(md5) == 16 {
options.HTTPHeaders.BlobContentMD5 = md5
} else {
log.Warnf("Invalid MD5 hash: %s, error: %v", base64MD5, err)
}
}
// Track upload progress // Track upload progress
progressTracker := &progressTracker{ progressTracker := &progressTracker{
total: stream.GetSize(), total: stream.GetSize(),