@@ -1264,7 +1264,7 @@ func (p *Posix) CreateMultipartUpload(ctx context.Context, mpu s3response.Create
1264
1264
}
1265
1265
}
1266
1266
1267
- err = p .storeObjectMetadata (nil , bucket , filepath .Join (objdir , uploadID ), ObjectMetadata {
1267
+ err = p .storeObjectMetadata (nil , bucket , filepath .Join (objdir , uploadID ), objectMetadata {
1268
1268
ContentType : mpu .ContentType ,
1269
1269
ContentEncoding : mpu .ContentEncoding ,
1270
1270
ContentDisposition : mpu .ContentDisposition ,
@@ -1540,7 +1540,7 @@ func (p *Posix) CompleteMultipartUpload(ctx context.Context, input *s3.CompleteM
1540
1540
upiddir := filepath .Join (objdir , uploadID )
1541
1541
1542
1542
userMetaData := make (map [string ]string )
1543
- objMeta := p .loadObjectMetaData (bucket , upiddir , userMetaData )
1543
+ objMeta := p .loadObjectMetaData (bucket , upiddir , nil , userMetaData )
1544
1544
err = p .storeObjectMetadata (f .File (), bucket , object , objMeta )
1545
1545
if err != nil {
1546
1546
return nil , err
@@ -1822,7 +1822,7 @@ func (p *Posix) retrieveUploadId(bucket, object string) (string, [32]byte, error
1822
1822
return entries [0 ].Name (), sum , nil
1823
1823
}
1824
1824
1825
- type ObjectMetadata struct {
1825
+ type objectMetadata struct {
1826
1826
ContentType * string
1827
1827
ContentEncoding * string
1828
1828
ContentDisposition * string
@@ -1833,10 +1833,10 @@ type ObjectMetadata struct {
1833
1833
1834
1834
// fill out the user metadata map with the metadata for the object
1835
1835
// and return object meta properties as `ObjectMetadata`
1836
- func (p * Posix ) loadObjectMetaData (bucket , object string , m map [string ]string ) ObjectMetadata {
1836
+ func (p * Posix ) loadObjectMetaData (bucket , object string , fi * os. FileInfo , m map [string ]string ) objectMetadata {
1837
1837
ents , err := p .meta .ListAttributes (bucket , object )
1838
1838
if err != nil || len (ents ) == 0 {
1839
- return ObjectMetadata {}
1839
+ return objectMetadata {}
1840
1840
}
1841
1841
1842
1842
if m != nil {
@@ -1856,13 +1856,20 @@ func (p *Posix) loadObjectMetaData(bucket, object string, m map[string]string) O
1856
1856
}
1857
1857
}
1858
1858
1859
- var result ObjectMetadata
1859
+ var result objectMetadata
1860
1860
1861
1861
b , err := p .meta .RetrieveAttribute (nil , bucket , object , contentTypeHdr )
1862
1862
if err == nil {
1863
1863
result .ContentType = backend .GetPtrFromString (string (b ))
1864
1864
}
1865
1865
1866
+ if (result .ContentType == nil || * result .ContentType == "" ) && fi != nil {
1867
+ if (* fi ).IsDir () {
1868
+ // this is the media type for directories in AWS and Nextcloud
1869
+ result .ContentType = backend .GetPtrFromString ("application/x-directory" )
1870
+ }
1871
+ }
1872
+
1866
1873
b , err = p .meta .RetrieveAttribute (nil , bucket , object , contentEncHdr )
1867
1874
if err == nil {
1868
1875
result .ContentEncoding = backend .GetPtrFromString (string (b ))
@@ -1891,7 +1898,7 @@ func (p *Posix) loadObjectMetaData(bucket, object string, m map[string]string) O
1891
1898
return result
1892
1899
}
1893
1900
1894
- func (p * Posix ) storeObjectMetadata (f * os.File , bucket , object string , m ObjectMetadata ) error {
1901
+ func (p * Posix ) storeObjectMetadata (f * os.File , bucket , object string , m objectMetadata ) error {
1895
1902
if getString (m .ContentType ) != "" {
1896
1903
err := p .meta .StoreAttribute (f , bucket , object , contentTypeHdr , []byte (* m .ContentType ))
1897
1904
if err != nil {
@@ -2252,7 +2259,7 @@ func (p *Posix) ListParts(ctx context.Context, input *s3.ListPartsInput) (s3resp
2252
2259
2253
2260
userMetaData := make (map [string ]string )
2254
2261
upiddir := filepath .Join (objdir , uploadID )
2255
- p .loadObjectMetaData (bucket , upiddir , userMetaData )
2262
+ p .loadObjectMetaData (bucket , upiddir , nil , userMetaData )
2256
2263
2257
2264
return s3response.ListPartsResult {
2258
2265
Bucket : bucket ,
@@ -2914,7 +2921,7 @@ func (p *Posix) PutObject(ctx context.Context, po s3response.PutObjectInput) (s3
2914
2921
return s3response.PutObjectOutput {}, fmt .Errorf ("set etag attr: %w" , err )
2915
2922
}
2916
2923
2917
- err = p .storeObjectMetadata (f .File (), * po .Bucket , * po .Key , ObjectMetadata {
2924
+ err = p .storeObjectMetadata (f .File (), * po .Bucket , * po .Key , objectMetadata {
2918
2925
ContentType : po .ContentType ,
2919
2926
ContentEncoding : po .ContentEncoding ,
2920
2927
ContentLanguage : po .ContentLanguage ,
@@ -3447,7 +3454,7 @@ func (p *Posix) GetObject(_ context.Context, input *s3.GetObjectInput) (*s3.GetO
3447
3454
if fi .IsDir () {
3448
3455
userMetaData := make (map [string ]string )
3449
3456
3450
- objMeta := p .loadObjectMetaData (bucket , object , userMetaData )
3457
+ objMeta := p .loadObjectMetaData (bucket , object , & fi , userMetaData )
3451
3458
b , err := p .meta .RetrieveAttribute (nil , bucket , object , etagkey )
3452
3459
etag := string (b )
3453
3460
if err != nil {
@@ -3497,7 +3504,7 @@ func (p *Posix) GetObject(_ context.Context, input *s3.GetObjectInput) (*s3.GetO
3497
3504
3498
3505
userMetaData := make (map [string ]string )
3499
3506
3500
- objMeta := p .loadObjectMetaData (bucket , object , userMetaData )
3507
+ objMeta := p .loadObjectMetaData (bucket , object , & fi , userMetaData )
3501
3508
3502
3509
b , err := p .meta .RetrieveAttribute (nil , bucket , object , etagkey )
3503
3510
etag := string (b )
@@ -3708,7 +3715,7 @@ func (p *Posix) HeadObject(ctx context.Context, input *s3.HeadObjectInput) (*s3.
3708
3715
}
3709
3716
3710
3717
userMetaData := make (map [string ]string )
3711
- objMeta := p .loadObjectMetaData (bucket , object , userMetaData )
3718
+ objMeta := p .loadObjectMetaData (bucket , object , & fi , userMetaData )
3712
3719
3713
3720
b , err := p .meta .RetrieveAttribute (nil , bucket , object , etagkey )
3714
3721
etag := string (b )
@@ -3901,7 +3908,7 @@ func (p *Posix) CopyObject(ctx context.Context, input *s3.CopyObjectInput) (*s3.
3901
3908
}
3902
3909
3903
3910
mdmap := make (map [string ]string )
3904
- p .loadObjectMetaData (srcBucket , srcObject , mdmap )
3911
+ p .loadObjectMetaData (srcBucket , srcObject , & fi , mdmap )
3905
3912
3906
3913
var etag string
3907
3914
var version * string
0 commit comments