github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/objectstorage/v1/objects/doc.go (about) 1 /* 2 Package objects contains functionality for working with Object Storage 3 object resources. An object is a resource that represents and contains data 4 - such as documents, images, and so on. You can also store custom metadata 5 with an object. 6 7 Note: When referencing the Object Storage API docs, some of the API actions 8 are listed under "containers" rather than "objects". This was an intentional 9 design in Gophercloud to make some object actions feel more natural. 10 11 Example to List Objects 12 13 containerName := "my_container" 14 15 listOpts := objects.ListOpts{ 16 Full: true, 17 } 18 19 allPages, err := objects.List(objectStorageClient, containerName, listOpts).AllPages() 20 if err != nil { 21 panic(err) 22 } 23 24 allObjects, err := objects.ExtractInfo(allPages) 25 if err != nil { 26 panic(err) 27 } 28 29 for _, object := range allObjects { 30 fmt.Printf("%+v\n", object) 31 } 32 33 Example to List Object Names 34 35 containerName := "my_container" 36 37 listOpts := objects.ListOpts{ 38 Full: false, 39 } 40 41 allPages, err := objects.List(objectStorageClient, containerName, listOpts).AllPages() 42 if err != nil { 43 panic(err) 44 } 45 46 allObjects, err := objects.ExtractNames(allPages) 47 if err != nil { 48 panic(err) 49 } 50 51 for _, object := range allObjects { 52 fmt.Printf("%+v\n", object) 53 } 54 55 Example to Create an Object 56 57 content := "some object content" 58 objectName := "my_object" 59 containerName := "my_container" 60 61 createOpts := objects.CreateOpts{ 62 ContentType: "text/plain" 63 Content: strings.NewReader(content), 64 } 65 66 object, err := objects.Create(objectStorageClient, containerName, objectName, createOpts).Extract() 67 if err != nil { 68 panic(err) 69 } 70 71 Example to Copy an Object 72 73 objectName := "my_object" 74 containerName := "my_container" 75 76 copyOpts := objects.CopyOpts{ 77 Destination: "/newContainer/newObject", 78 } 79 80 object, err := objects.Copy(objectStorageClient, containerName, objectName, copyOpts).Extract() 81 if err != nil { 82 panic(err) 83 } 84 85 Example to Delete an Object 86 87 objectName := "my_object" 88 containerName := "my_container" 89 90 object, err := objects.Delete(objectStorageClient, containerName, objectName).Extract() 91 if err != nil { 92 panic(err) 93 } 94 95 Example to Download an Object's Data 96 97 objectName := "my_object" 98 containerName := "my_container" 99 100 object := objects.Download(objectStorageClient, containerName, objectName, nil) 101 if object.Err != nil { 102 panic(object.Err) 103 } 104 // if "ExtractContent" method is not called, the HTTP connection will remain consumed 105 content, err := object.ExtractContent() 106 if err != nil { 107 panic(err) 108 } 109 */ 110 package objects