Creating a Folder
API Description
There is no folder in its real meaning in OBS. All elements in buckets are objects. To create a folder in OBS is essentially to create an object whose size is 0 and whose name ends with a slash (/). Such objects have no difference from other objects and can be downloaded and deleted, except that they are displayed as folders in OBS Console.
Method Definition
func (obsClient ObsClient) PutObject(input *PutObjectInput) (output *PutObjectOutput, err error)
Method Definition If a Signed URL Is Used
func (obsClient ObsClient) PutObjectWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *PutObjectOutput, err error)
Request Parameters
| Field | Type | Optional or Mandatory |
|---|---|---|
| input | Mandatory |
Returned Results
| Field | Type |
|---|---|
| output | |
| err | error |
Sample Code
func main() { input := &obs.PutObjectInput{} input.Bucket = "bucketname" input.Key = "parent_directory/" // Create a folder. output, err := obsClient.PutObject(input) if err == nil { fmt.Printf("RequestId:%s\n", output.RequestId) } else if obsError, ok := err.(obs.ObsError); ok { fmt.Printf("Code:%s\n", obsError.Code) fmt.Printf("Message:%s\n", obsError.Message) } input.Key = "parent_directory/objectname" input.Body = strings.NewReader("Hello OBS") // Create a folder. output, err = obsClient.PutObject(input) if err == nil { fmt.Printf("RequestId:%s\n", output.RequestId) } else if obsError, ok := err.(obs.ObsError); ok { fmt.Printf("Code:%s\n", obsError.Code) fmt.Printf("Message:%s\n", obsError.Message) } }
- To create a folder in OBS is to create an object whose size is 0 and whose name ends with a slash (/), in essential.
- To create a multi-level folder, you only need to create the folder with the last level. For example, if you want to create a folder named src1/src2/src3/, create it directly, no matter whether the src1/ and src1/src2/ folders exist.
Last Article: Downloading Objects - Resumable Transfer
Next Article: Copying an Object
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.