AnthonyMDev / AmazonS3RequestManager

A request manager that uses Alamofire to serialize requests to the AWS S3 (Amazon Simple Storage Solution). Based on AFAmazonS3Manager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"NoSuchKey" error on downloading a file

Jon-GHI opened this issue · comments

Anthony, First of all, thanks for the very useful code you've submitted. I've written a small app (iOS 9.1, Xcode 7.1.1) to test upload/download/delete functionality. Uploading files to an S3 bucket and deleting them from the S3 bucket works fine.

However, I get an error "NoSuchKey" every time I try to download a file using ".downloadObject". The credentials are fine, because I can upload and delete with no problem. I verified that I successfully uploaded "anothertest.txt" to my bucket. The file contents are "This is a test". Here's a code snippet:

    // This works fine
    func UploadToCloud(theFileName: String, theContents: NSString) {
        let theData: NSData = theContents.dataUsingEncoding(NSUTF8StringEncoding)!
        amazonS3Manager.putObject(theData, destinationPath: theFileName)
    }

    // This fails every time with the same error
    func DownloadToFile(theFileName: String) {
        let destination: NSURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0].URLByAppendingPathComponent(theFileName)
        print(destination.path!)
        amazonS3Manager.downloadObject(theFileName, saveToURL: destination)

        // quick hack to wait for completion
        sleep(3)

        // now read contents of file and print it
        print(ReadTextFile(destination.path!))
    }

-----------------------------------------------------------------------------------------------
  The debug print statements produce the following:
/var/mobile/Containers/Data/Application/4FF3BA62-A446-4BD9-B260-7707A67ED74E/Documents/another.txt
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>anothertest.txt</Key><RequestId>118C265C26691052</RequestId><HostId>m2hed5lY29uSZccvG8O+rtHDln24PTpmbhNEaRvI3fS3V6rGZw2zdAevUjvEl7W+/rTu9mjj1mM=</HostId></Error>

Any idea what's wrong? Is this an Amazon S3 issue? Any help would be appreciated. Thanks!
Jon

I found the problem. I had misspelled the filename in the ".downloadObject" request! I apologize the false report. The code seems to work just fine.

Thanks for following up @Jon-GHI. Glad to hear everything is working for you!