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

Method PutObject

api-put-object.go:329–391  ·  view source on GitHub ↗

PutObject creates an object in a bucket. You must have WRITE permissions on a bucket to create an object. - For size smaller than 16MiB PutObject automatically does a single atomic PUT operation. - For size larger than 16MiB PutObject automatically does a multipart upload operation. - For size i

(ctx context.Context, bucketName, objectName string, reader io.Reader, size int64,
	opts PutObjectOptions,
)

Source from the content-addressed store, hash-verified

327//
328// NOTE: Upon errors during upload multipart operation is entirely aborted.
329func (c *Client) PutObject(ctx context.Context, bucketName, objectName string, reader io.Reader, size int64,
330 opts PutObjectOptions,
331) (info UploadInfo, err error) {
332 if opts.RDMABuffer != nil && c.rdmaEnabled {
333 return c.putObjectRDMA(ctx, bucketName, objectName, opts)
334 }
335 if size < 0 && opts.DisableMultipart {
336 return UploadInfo{}, errors.New("object size must be provided with disable multipart upload")
337 }
338
339 err = opts.validate(c)
340 if err != nil {
341 return UploadInfo{}, err
342 }
343
344 // Check for largest object size allowed.
345 if size > int64(maxObjectSize) {
346 return UploadInfo{}, errEntityTooLarge(size, maxObjectSize, bucketName, objectName)
347 }
348
349 if opts.Checksum.IsSet() {
350 opts.AutoChecksum = opts.Checksum
351 opts.SendContentMd5 = false
352 }
353
354 if c.trailingHeaderSupport {
355 opts.AutoChecksum.SetDefault(ChecksumCRC32C)
356 addAutoChecksumHeaders(&opts)
357 }
358
359 // NOTE: Streaming signature is not supported by GCS.
360 if s3utils.IsGoogleEndpoint(*c.endpointURL) {
361 return c.putObject(ctx, bucketName, objectName, reader, size, opts)
362 }
363
364 partSize := opts.PartSize
365 if opts.PartSize == 0 {
366 partSize = minPartSize
367 }
368
369 if c.overrideSignerType.IsV2() {
370 if size >= 0 && size < int64(partSize) || opts.DisableMultipart {
371 return c.putObject(ctx, bucketName, objectName, reader, size, opts)
372 }
373 return c.putObjectMultipart(ctx, bucketName, objectName, reader, size, opts)
374 }
375
376 if size < 0 {
377 if opts.DisableMultipart {
378 return UploadInfo{}, errors.New("no length provided and multipart disabled")
379 }
380 if opts.ConcurrentStreamParts && opts.NumThreads > 1 {
381 return c.putObjectMultipartStreamParallel(ctx, bucketName, objectName, reader, opts)
382 }
383 return c.putObjectMultipartStreamNoLength(ctx, bucketName, objectName, reader, opts)
384 }
385
386 if size <= int64(partSize) || opts.DisableMultipart {

Calls 13

putObjectRDMAMethod · 0.95
putObjectMethod · 0.95
putObjectMultipartMethod · 0.95
IsGoogleEndpointFunction · 0.92
errEntityTooLargeFunction · 0.85
addAutoChecksumHeadersFunction · 0.85
SetDefaultMethod · 0.80
IsV2Method · 0.80
validateMethod · 0.45

Tested by

no test coverage detected