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

  • SEARCH
  • Home
  • 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 8769857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:26:33+00:00 2026-06-13T17:26:33+00:00

I am using amazon web services to upload images. I am not able to

  • 0

I am using amazon web services to upload images. I am not able to access a value out of the GCD block. How should i access the value of “myString” in some other class?

My code:

-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
{
    AppDelegate *del = [[UIApplication sharedApplication]delegate];
    if(indicatorView!=nil)
    {
        [indicatorView removeFromSuperview];
        indicatorView=nil;
    }

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Upload Completed" message:@"The image was successfully uploaded." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
    [alert show];

    //del.fileName = url;

    // Set the content type so that the browser will treat the URL as an image.
    /*S3ResponseHeaderOverrides *override = [[S3ResponseHeaderOverrides alloc] init];
    override.contentType = @"image/jpeg";

    // Request a pre-signed URL to picture that has been uplaoded.
    S3GetPreSignedURLRequest *gpsur = [[S3GetPreSignedURLRequest alloc] init];
    gpsur.key = @"NameOfThePicture";
    //del.fileName = gpsur.key;
    gpsur.bucket = @"pic-bucket";
    gpsur.expires = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval) 3600]; // Added an hour's worth of seconds to the current time.

    gpsur.responseHeaderOverrides = override;

    // Get the URL
    NSError *error;
    url = [self.s3 getPreSignedURL:gpsur error:&error];
    NSString *myString = [url absoluteString];

    NSLog(@"myStringgg====>%@",myString);
    del.fileName = myString;
    NSLog(@"URL=====>%@",url);*/



    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(queue, ^
    {

        // Set the content type so that the browser will treat the URL as an image.
        S3ResponseHeaderOverrides *override = [[S3ResponseHeaderOverrides alloc] init];
        override.contentType = @"image/jpeg";

        // Request a pre-signed URL to picture that has been uplaoded.
        S3GetPreSignedURLRequest *gpsur = [[S3GetPreSignedURLRequest alloc] init];
        gpsur.key = @"NameOfThePicture";
        //del.fileName = gpsur.key;
        gpsur.bucket = @"pic-bucket";
        gpsur.expires = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval) 3600]; // Added an hour's worth of seconds to the current time.

        gpsur.responseHeaderOverrides = override;

        // Get the URL
        NSError *error;
        NSURL *url = [self.s3 getPreSignedURL:gpsur error:&error];
        NSString *myString = [url absoluteString];
        //del.fileName = myString;
        NSLog(@"URL=====>%@",url);

        if(url == nil)
        {
            if(error != nil)
            {
                dispatch_async(dispatch_get_main_queue(), ^{

                    NSLog(@"Error: %@", error);
                    //[self showAlertMessage:[error.userInfo objectForKey:@"message"] withTitle:@"Browser Error"];
                });
            }
        }
        else
        {
            dispatch_async(dispatch_get_main_queue(), ^{

                //del.fileName = myString;

                //NSLog(@"haURL===>%@",del.fileName);
            });

            del.fileName = myString;
        }


    //NSLog(@"nameURL====>%@",url);
    });




}

Now i want to access “myString” var so that i can access its value in other class. Thanks

Property declarations:

@property(nonatomic,strong)NSString *fileName; //in appdelegate.h
@property(nonatomic,strong) NSString *File; //in the same controller as GCD

Update:

    PictureViewController *pic = [[PictureViewController alloc]init];


        **NSLog(@"newNameeee====>%@",pic.File);**


        AppDelegate *del = [[UIApplication sharedApplication]delegate];
        NSLog(@"LocatedAt====>%@",del.locatedAt);


        NSLog(@"FileSize====>%d",del.fileSize);
        **NSLog(@"FileName====>%@",del.fileName);**
  • 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-06-13T17:26:34+00:00Added an answer on June 13, 2026 at 5:26 pm

    The problem is that you try to access the del.fileName before the async part of the request:didCompleteWithResponse: finishes.

    Try the following: modify your code slightly be moving the del.fileName = myString to the dispatch block on the main tread:

    -(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
    {
        AppDelegate *del = [[UIApplication sharedApplication]delegate];
        if(indicatorView!=nil)
        {
            [indicatorView removeFromSuperview];
            indicatorView=nil;
        }
    
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Upload Completed" message:@"The image was successfully uploaded." delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
        [alert show];
    
        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
        dispatch_async(queue, ^
        {
    
            // Set the content type so that the browser will treat the URL as an image.
            S3ResponseHeaderOverrides *override = [[S3ResponseHeaderOverrides alloc] init];
            override.contentType = @"image/jpeg";
    
            // Request a pre-signed URL to picture that has been uplaoded.
            S3GetPreSignedURLRequest *gpsur = [[S3GetPreSignedURLRequest alloc] init];
            gpsur.key = @"NameOfThePicture";
            //del.fileName = gpsur.key;
            gpsur.bucket = @"pic-bucket";
            gpsur.expires = [NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval) 3600]; // Added an hour's worth of seconds to the current time.
    
            gpsur.responseHeaderOverrides = override;
    
            // Get the URL
            NSError *error;
            NSURL *url = [self.s3 getPreSignedURL:gpsur error:&error];
            NSString *myString = [url absoluteString];
            //del.fileName = myString;
            NSLog(@"URL=====>%@",url);
    
            if(url == nil)
            {
                if(error != nil)
                {
                    dispatch_async(dispatch_get_main_queue(), ^{
    
                        NSLog(@"Error: %@", error);
                        //[self showAlertMessage:[error.userInfo objectForKey:@"message"] withTitle:@"Browser Error"];
                    });
                }
            }
            else
            {
                dispatch_async(dispatch_get_main_queue(), ^{
    
                    del.fileName = myString;
                    [del didReceivePictureFilename];
                });
            }
        });
    }
    

    Than you declare the didReceivePictureFilename in your AppDelegate and move the accessing part of your code to that method. But you have to do the part where you start the upload some place else. (The code in your question doesn’t show that part)

    Of course you could also omit the fileName property entirely and hand the filename directly in the didReceivePictureFilename callback:

    [del didReceivePictureFilename:myString];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading about and using the Amazon Web Services, I'm not really able to grasp
I'm trying to send mass mails using Amazon SES web services. However, I'm not
I've got a website running on Amazon Web Services that is deployed using Elastic
I am using Amazon web services in my php application. Is it safe to
I'm playing around with using amazon web services in my personal project. I've grabbed
I am developing a web application that uses Amazon Web Services. I am using
I'm using Amazon Web Services' PHP SDK for their Flexible Payments System. Somewhere in
I'm using rJava to speak to the Amazon Web Services Java API from inside
I'm using Amazon Web Services for nearly everything, including their SimpleDB flat database. It's
I need big help from you,I want to upload image using amazon s3 web

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.