Update the object with the contents of the io.Reader, modTime and size The new object may have been created if an error is returned
(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption)
| 1431 | // |
| 1432 | // The new object may have been created if an error is returned |
| 1433 | func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (err error) { |
| 1434 | bucket, bucketPath := o.split() |
| 1435 | // Create parent dir/bucket if not saving directory marker |
| 1436 | if !strings.HasSuffix(o.remote, "/") { |
| 1437 | err = o.fs.mkdirParent(ctx, o.remote) |
| 1438 | if err != nil { |
| 1439 | return err |
| 1440 | } |
| 1441 | } |
| 1442 | modTime := src.ModTime(ctx) |
| 1443 | |
| 1444 | object := storage.Object{ |
| 1445 | Bucket: bucket, |
| 1446 | Name: bucketPath, |
| 1447 | ContentType: fs.MimeType(ctx, src), |
| 1448 | Metadata: metadataFromModTime(modTime), |
| 1449 | } |
| 1450 | // Set the storage class from config if configured |
| 1451 | if o.fs.opt.StorageClass != "" { |
| 1452 | object.StorageClass = o.fs.opt.StorageClass |
| 1453 | } |
| 1454 | // Apply upload options |
| 1455 | for _, option := range options { |
| 1456 | key, value := option.Header() |
| 1457 | lowerKey := strings.ToLower(key) |
| 1458 | switch lowerKey { |
| 1459 | case "": |
| 1460 | // ignore |
| 1461 | case "cache-control": |
| 1462 | object.CacheControl = value |
| 1463 | case "content-disposition": |
| 1464 | object.ContentDisposition = value |
| 1465 | case "content-encoding": |
| 1466 | object.ContentEncoding = value |
| 1467 | case "content-language": |
| 1468 | object.ContentLanguage = value |
| 1469 | case "content-type": |
| 1470 | object.ContentType = value |
| 1471 | case "x-goog-storage-class": |
| 1472 | object.StorageClass = value |
| 1473 | default: |
| 1474 | const googMetaPrefix = "x-goog-meta-" |
| 1475 | if strings.HasPrefix(lowerKey, googMetaPrefix) { |
| 1476 | metaKey := lowerKey[len(googMetaPrefix):] |
| 1477 | object.Metadata[metaKey] = value |
| 1478 | } else { |
| 1479 | fs.Errorf(o, "Don't know how to set key %q on upload", key) |
| 1480 | } |
| 1481 | } |
| 1482 | } |
| 1483 | var newObject *storage.Object |
| 1484 | err = o.fs.pacer.CallNoRetry(func() (bool, error) { |
| 1485 | insertObject := o.fs.svc.Objects.Insert(bucket, &object).Media(in, googleapi.ContentType("")).Name(object.Name) |
| 1486 | if !o.fs.opt.BucketPolicyOnly { |
| 1487 | insertObject.PredefinedAcl(o.fs.opt.ObjectACL) |
| 1488 | } |
| 1489 | insertObject = insertObject.Context(ctx) |
| 1490 | if o.fs.opt.UserProject != "" { |
no test coverage detected