Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6870449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:41:06+00:00 2026-05-27T03:41:06+00:00

I am using the AWS SDK for iOS to upload and download files to

  • 0

I am using the AWS SDK for iOS to upload and download files to and from local hard drive to Amazon S3 storage. I am capable of making this work but I am unable to get the S3 delegate to respond properly to alert me when operations have finished or resulted in an error.

I have an array of files that I want to upload. For each file I create a NSOperation where the main routine consist mostly of:

    AmazonCredentials * credentials = [[AmazonCredentials alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
    putObjectRequest = [[S3PutObjectRequest alloc] initWithKey:pathCopy inBucket:[self bucket]];
    putObjectRequest.filename = pathSource;
    putObjectRequest.credentials=credentials;
    [putObjectRequest setDelegate:s3Delegate];

Here, the delegate (s3Delegate) is created as a regular AmazonServiceRequestDelegate which should be able to fire off responses when an operation has finished. Each of my NSOperations are added to my NSOperationQueue which executes operations non-concurrently. If I use the delegate [putObjectRequest setDelegate:s3Delegate] the operations are not working. If I remove the use of the delegate the operations are performed correctly but I am unable to receive any responses to the operations as I do not have a delegate.

If I remove the use of the NSOperationQueue completely and use the [putObjectRequest setDelegate:s3Delegate] the delegate works perfectly.

My question is what am I doing wrong with using a delegate in a queue? Since the delegate is perfectly capable of performing while not in a queue could this be related to not performing on the main thread? I really want to be able to use the queue to limit the number of non-concurrent operations, however I am unable to figure this out. I hope someone has an idea of what is going on here and any example code would be greatly appreciated. Thanks!
Cheers, Trond

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:41:06+00:00Added an answer on May 27, 2026 at 3:41 am

    It seems that the aws sdk behaves asynchronously after the time you set your delegate.
    So in order to have your asynchronous aws stuff work in a (asynchronous) NSOperation, you got to put some magic to wait for AWS to complete:

    In your .h NSOperation file, add a boolean:

    @interface UploadOperation : NSOperation <AmazonServiceRequestDelegate> {
        @private
        BOOL        _doneUploadingToS3;
    }
    

    and in your .m file, your main method will look like this:

    - (void) main
    {   
        ....  do your stuff …..
    
        _doneUploadingToS3 = NO;
    
        S3PutObjectRequest *por = nil;
        AmazonS3Client *s3Client = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY withSecretKey:SECRET_KEY];
        s3Client.endpoint = endpoint;
    
        @try {
            por = [[[S3PutObjectRequest alloc] initWithKey:KEY inBucket:BUCKET] autorelease];
            por.delegate = self;
            por.contentType = @"image/jpeg";
            por.data = _imageData;
    
            [s3Client putObject:por];
        }
        @catch (AmazonClientException *exception) {
            _doneUploadingToS3 = YES;
        }
    
        do {
            [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
        } while (!_doneUploadingToS3);
    
        por.delegate = nil;
    
        ....  continue with your stuff ….
    }
    

    do not forget to implement your delegate methods

    -(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
    {
        _doneUploadingToS3 = YES;
    }
    
    -(void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)error 
    {
        _doneUploadingToS3 = YES;
    }
    
    -(void)request:(AmazonServiceRequest *)request didFailWithServiceException:(NSException *)exception 
    {
        _doneUploadingToS3 = YES;
    }
    
    - (void) request:(AmazonServiceRequest *)request didSendData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
    {
        // Do what you want
    }
    
    -(void)request:(AmazonServiceRequest *)request didReceiveResponse:(NSURLResponse *)response
    {
        // Do what you want
    }
    
    -(void)request:(AmazonServiceRequest *)request didReceiveData:(NSData *)data
    {
        // Do what you want
    }
    

    Note: this magic can work for any stuff that performs asynchronously but have to be implemented in a NSOperation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using AWS SDK for .NET to upload several images. Before making the PutObjectRequest,
I’m trying to upload files to Amazon S3 using AWS::S3 , but I’d like
Problem: I would like to download 100 files in parallel from AWS S3 using
I'm using the aws-sdk gem and I'm trying to basically upload a really large
How do i start and stop an amazon EC2 instance programmatically using aws-sdk in
I'm trying to start a Amazon EC2 cloud machine with [startInstance][2] method using aws-sdk
I tried using the AWS console, but after making a few 100 files public
I wrote a quick objective-C method that uses Amazon's AWS iOS SDK to synchronously
I'm using the Amazon AWS .NET SDK v1.2.1. The following code throws an exception
I'm using the AWS SDK for PHP, specifically the Amazon S3 portion, and I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.