'upload json file to aws3 using Swift/Xcode

I have generated a json file on Xcode. But having difficulty uploading it onto aws.

the code I have used is something like this:

func upload2aws(fileUrl: URL) {
    let awsTransferUtility = AWSS3TransferUtility.default()
    var completionHandler : AWSS3TransferUtilityUploadCompletionHandlerBlock?
    let expression = AWSS3TransferUtilityUploadExpression()
    
    awsTransferUtility.uploadFile(fileUrl, bucket: "thebucketname", key: "key1", contentType: "file", expression: expression, completionHandler: completionHandler).continueWith { (AWStask) -> Any? in
        if let error = AWStask.error {
            print("S3 upload error")
            print("error is: \(error.localizedDescription)")
        }
        print("uploaded")
        if AWStask.result != nil {
            let fileUrl = AWSS3.default().configuration.endpoint.url
            
        }
  }

The error thrown: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The service configuration is nil. You need to configure Info.plist or set defaultServiceConfiguration before using this method.'



Solution 1:[1]

Like it's mentioned in the error, you need to set up a configuration with AWS credentials. Better idea and configuration setup on enter link description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ahmed Rauf Khan