// create an instance of the ServiceClient client,err := openstack.NewClient(authURL,opts) // authenticate with credentials err = openstack.Authenticate(client, authOpts) // create the Object Storage service client objectStorage, err := openstack.NewObjectStorageV1(client, gophercloud.EndpointOpts{}) // open the file to be uploaded file, err := os.Open("/path/to/file") // create the PutObjectOpts opts := &gophercloud.ObjectCreateOpts{ ContentType: "application/octet-stream", } // use the Put method to upload the file to Swift putResp := objectstorage.PutObject(containerName, objectName, file, opts)
// create an instance of the ServiceClient client, _ := session.NewSession(&aws.Config{ Region: aws.String("us-west-2"), }) // create the S3 service client s3 := s3.New(client) // create the PutObjectInput input := &s3.PutObjectInput{ Bucket: aws.String("my-bucket"), Key: aws.String("my-object"), Body: bytes.NewReader([]byte("hello world")), Metadata: map[string]*string{ "my-metadata-header": aws.String("metadata-value"), }, } // use the PutObject method to upload the file to S3 with the custom metadata header _, err := s3.PutObject(input)In this example, the code creates an instance of the ServiceClient, then creates the S3 service client. It then sets the custom metadata header for the object using the PutObjectInput.Metadata parameter, and finally uses the PutObject method to upload the object to the specified bucket and object name.