Add folder in Amazon s3 bucket

前端 未结 16 1343
青春惊慌失措
青春惊慌失措 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: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")
    

提交回复
热议问题