Description
Bug Report
- import path of package in question, e.g.
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
- SDK version e.g.
github.com/Azure/azure-sdk-for-go/sdk/storage/azfile v1.5.1
- output of
go version
- go version go1.24.3 darwin/arm64
- What happened?
When I use fileClient.Create and pass PermissionKey as an optional parameter then it throws an error, but when I use
fileClient.SetHTTPHeaders it is working fine.
_2025/05/14 09:52:08 Failed to upload file with metadata: failed to create file: PUT https://ashukdemostorage.file.core.windows.net/testsmallfiles/b_file_001.txt
RESPONSE 400: 400 An HTTP header that's mandatory for this request is not specified.
ERROR CODE: MissingRequiredHeader
MissingRequiredHeader
An HTTP header that's mandatory for this request is not specified.
RequestId:9b764489-501a-00d9-5f87-c4d250000000
Time:2025-05-14T04:22:08.0641516Zx-ms-file-permission
exit status 1_
`
func uploadFileWithMetadata(ctx context.Context, shareClient *share.Client, localFilePath, targetFilePath string, fileProps *file.GetPropertiesResponse) error {
// Create a file client
fileClient := shareClient.NewRootDirectoryClient().NewFileClient(targetFilePath)
// Open the local file
localFile, err := os.Open(localFilePath)
if err != nil {
return fmt.Errorf("failed to open local file: %v", err)
}
defer localFile.Close()
// Get file info
fileInfo, err := localFile.Stat()
if err != nil {
return fmt.Errorf("failed to get file info: %v", err)
}
// Pretty print file properties as JSON
filePropsJSON, err := json.MarshalIndent(fileProps, "", " ")
if err != nil {
fmt.Printf("Error marshaling file properties to JSON: %v\n", err)
} else {
fmt.Printf("File Properties JSON:\n%s\n", string(filePropsJSON))
}
ntfsAttributes, err := parseFileAttributes(fileProps.FileAttributes)
if err != nil {
fmt.Printf("Error parsing file attributes: %v\n", err)
} else {
fmt.Printf("NTFS File Attributes:\n%#v\n", ntfsAttributes)
}
// Create the file with metadata
_, err = fileClient.Create(ctx, fileInfo.Size(), &file.CreateOptions{
HTTPHeaders: &file.HTTPHeaders{
CacheControl: fileProps.CacheControl,
ContentDisposition: fileProps.ContentDisposition,
ContentEncoding: fileProps.ContentEncoding,
ContentLanguage: fileProps.ContentLanguage,
ContentType: fileProps.ContentType,
},
SMBProperties: &file.SMBProperties{
Attributes: &ntfsAttributes,
CreationTime: fileProps.FileCreationTime,
LastWriteTime: fileProps.FileLastWriteTime,
ChangeTime: fileProps.FileChangeTime,
},
Permissions: &file.Permissions{
// Either Permission or PermissionKey can be set, not both
// Permission is set if permission size is < 8kb
// Otherwise PermissionKey can be set by default
PermissionKey: fileProps.FilePermissionKey,
},
Metadata: fileProps.Metadata,
})
if err != nil {
return fmt.Errorf("failed to create file: %v", err)
}
// Upload the file content
err = fileClient.UploadFile(ctx, localFile, &file.UploadFileOptions{
ChunkSize: 1024 * 1024 * 10, // 10MB
Progress: func(bytesTransferred int64) {
fmt.Printf("Uploaded %d bytes\n", bytesTransferred)
},
Concurrency: 10,
})
if err != nil {
return fmt.Errorf("failed to upload file: %v", err)
}
fileClient.SetHTTPHeaders(ctx, &file.SetHTTPHeadersOptions{
Permissions: &file.Permissions{
// Either Permission or PermissionKey can be set, not both
// Permission is set if permission size is < 8kb
// Otherwise PermissionKey can be set by default
PermissionKey: fileProps.FilePermissionKey,
},
})
return nil
}
`
- What did you expect or want to happen?
I expect that the PermissionKey should be set in the create call itself rather than explicitly calling another API.
Also the Permission var is not provided in the GetProperties response.
-
How can we reproduce it?
Sample code is provided just pass the permissionKey in the Create API call. The issue is easily reproducible -
Anything we should know about your environment.
Just a POC code running on dev machine.