MCPcopy
hub / github.com/minio/minio-go / FPutObject

Method FPutObject

api-put-object-file-context.go:30–64  ·  view source on GitHub ↗

FPutObject - Create an object in a bucket, with contents from file at filePath. Allows request cancellation.

(ctx context.Context, bucketName, objectName, filePath string, opts PutObjectOptions)

Source from the content-addressed store, hash-verified

28
29// FPutObject - Create an object in a bucket, with contents from file at filePath. Allows request cancellation.
30func (c *Client) FPutObject(ctx context.Context, bucketName, objectName, filePath string, opts PutObjectOptions) (info UploadInfo, err error) {
31 // Input validation.
32 if err := s3utils.CheckValidBucketName(bucketName); err != nil {
33 return UploadInfo{}, err
34 }
35 if err := s3utils.CheckValidObjectName(objectName); err != nil {
36 return UploadInfo{}, err
37 }
38
39 // Open the referenced file.
40 fileReader, err := os.Open(filePath)
41 // If any error fail quickly here.
42 if err != nil {
43 return UploadInfo{}, err
44 }
45 defer fileReader.Close()
46
47 // Save the file stat.
48 fileStat, err := fileReader.Stat()
49 if err != nil {
50 return UploadInfo{}, err
51 }
52
53 // Save the file size.
54 fileSize := fileStat.Size()
55
56 // Set contentType based on filepath extension if not given or default
57 // value of "application/octet-stream" if the extension has no associated type.
58 if opts.ContentType == "" {
59 if opts.ContentType = mime.TypeByExtension(filepath.Ext(filePath)); opts.ContentType == "" {
60 opts.ContentType = "application/octet-stream"
61 }
62 }
63 return c.PutObject(ctx, bucketName, objectName, fileReader, fileSize, opts)
64}

Callers 9

testFPutObjectMultipartFunction · 0.95
testFPutObjectFunction · 0.95
testFPutObjectContextFunction · 0.95
testFPutObjectContextV2Function · 0.95
testSSECEncryptionFPutFunction · 0.95
testSSES3EncryptionFPutFunction · 0.95
testFPutObjectV2Function · 0.95
mainFunction · 0.80
mainFunction · 0.80

Calls 5

PutObjectMethod · 0.95
CheckValidBucketNameFunction · 0.92
CheckValidObjectNameFunction · 0.92
StatMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected