Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support parsing content type when creating object #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions client/api_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,17 @@ func (c *Client) CreateObject(ctx context.Context, bucketName, objectName string
return "", err
}

// Read a small chunk to detect MIME type
peeker := make([]byte, types.BytesToReadForMIME)
n, err := reader.Read(peeker)
if err != nil && err != io.EOF {
return "", err
}

// Concatenate the peeked data with the original reader
combinedReader := io.MultiReader(bytes.NewReader(peeker[:n]), reader)
// compute hash root of payload
expectCheckSums, size, redundancyType, err := c.ComputeHashRoots(reader, opts.IsSerialComputeMode)
expectCheckSums, size, redundancyType, err := c.ComputeHashRoots(combinedReader, opts.IsSerialComputeMode)
if err != nil {
return "", err
}
Expand All @@ -125,9 +134,9 @@ func (c *Client) CreateObject(ctx context.Context, bucketName, objectName string
if opts.ContentType != "" {
contentType = opts.ContentType
} else {
contentType = types.ContentDefault
contentType = http.DetectContentType(peeker[:n])
}

var visibility storageTypes.VisibilityType
if opts.Visibility == storageTypes.VISIBILITY_TYPE_UNSPECIFIED {
visibility = storageTypes.VISIBILITY_TYPE_INHERIT // set default visibility type
Expand Down
1 change: 1 addition & 0 deletions types/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ const (

WaitTxContextTimeOut = 1 * time.Second
DefaultExpireSeconds = 1000
BytesToReadForMIME = 512
)
Loading