Add folder in Amazon s3 bucket

前端 未结 16 1361
青春惊慌失措
青春惊慌失措 2021-02-06 23:34

I want to add Folder in my amazon s3 bucket using coding. Can you please suggest me how to achieve this?

相关标签:
16条回答
  • 2021-02-07 00:04

    This is a divisive topic, so here is a screenshot in 2019 of the AWS S3 console for adding folders and the note:

    When you create a folder, S3 console creates an object with the above name appended by suffix "/" and that object is displayed as a folder in the S3 console.

    Then 'using coding' you can simply adjust the object name by prepending a valid folder name string and a forward slash.

    0 讨论(0)
  • 2021-02-07 00:04

    You can use copy command to create a folder while copy a file.

    aws s3 cp test.xml s3://mybucket/myfolder/test.xml
    
    0 讨论(0)
  • 2021-02-07 00:05

    in-order to create a directory inside s3 bucket and copy contents inside that is pretty simple.

    S3 command can be used: aws s3 cp abc/def.txt s3://mybucket/abc/

    Note: / is must that makes the directory, otherwise it will become a file in s3.

    0 讨论(0)
  • 2021-02-07 00:07

    For Swift I created a method where you pass in a String for the folder name.

    Swift 3:

    import AWSS3
    
    func createFolderWith(Name: String!) {
        let folderRequest: AWSS3PutObjectRequest = AWSS3PutObjectRequest()
        folderRequest.key = Name + "/"
        folderRequest.bucket = bucket
        AWSS3.default().putObject(folderRequest).continue({ (task) -> Any? in
            if task.error != nil {
                assertionFailure("* * * error: \(task.error?.localizedDescription)")
            } else {
                print("created \(Name) folder")
            }
            return nil
        })
    }
    

    Then just call

     createFolderWith(Name:"newFolder")
    
    0 讨论(0)
提交回复
热议问题