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 260049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:18:55+00:00 2026-05-11T22:18:55+00:00

I am pulling my hair out on this one… I am using the ASIHTTPRequest

  • 0

I am pulling my hair out on this one… I am using the ASIHTTPRequest (http://allseeing-i.com/ASIHTTPRequest/) wrapper library for accessing Amazon S3 storage. I am able to connect just fine and grab a listing of buckets without any problems. My frustration is with trying to UPLOAD (PUT and/or POST) a new object (a photo) to an existing bucket. I am following Amazon’s documentation to the letter, (at least I think I am.) but nothing seems to work.

Please, someone help me before I jump out of a window. I don’t want to die. 🙁

Thanks in advance for ANY help I can get.

L.

  • 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-11T22:18:55+00:00Added an answer on May 11, 2026 at 10:18 pm

    Here is a basic example using PUT. Obviously you should be using a queue rather than a synchronous request in the real world.

    If you change the amz headers, don’t forget to update ‘canonicalizedAmzHeaders’ as per Amazon’s instructions.

    #import "ASIHTTPRequest.h"
    #import <CommonCrypto/CommonHMAC.h>
    
    ...
    
    - (void)testS3
    {
       NSString *filePath = @"/path/to/file";
       NSString *contentType = @"text/plain";
       NSString *bucket = @"mybucket";
       NSString *path = @"test";
       NSString *secretAccessKey = @"my-secret-access-key";
       NSString *accessKey = @"my-access-key";
    
       NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
       [dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss zzzz"];
       NSString *date = [dateFormatter stringFromDate:[NSDate date]];
    
       ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@.s3.amazonaws.com/%@",bucket,path]]] autorelease];
       [request setPostBodyFilePath:filePath];
       [request setShouldStreamPostDataFromDisk:YES];
       [request setRequestMethod:@"PUT"];
    
       [request addRequestHeader:@"x-amz-acl" value:@"private"];
       [request addRequestHeader:@"Content-Type" value:contentType];
       [request addRequestHeader:@"Date" value:date];
    
       NSString *canonicalizedAmzHeaders = @"x-amz-acl:private";
       NSString *canonicalizedResource = [NSString stringWithFormat:@"/%@/%@",bucket,path];
       NSString *stringToSign = [NSString stringWithFormat:@"PUT\n\n%@\n%@\n%@\n%@",contentType,date,canonicalizedAmzHeaders,canonicalizedResource];
    
       NSString *signature = [self base64forData:[self HMACSHA1withKey:secretAccessKey forString:stringToSign]];
       NSString *auth = [NSString stringWithFormat:@"AWS %@:%@",accessKey,signature];
       [request addRequestHeader:@"Authorization" value:auth];
    
    
       [request start];
       NSLog(@"%@",[request responseString]);
    
    }
    
    
    // Source: http://stackoverflow.com/questions/476455/is-there-a-library-for-iphone-to-work-with-hmac-sha-1-encoding
    
    - (NSData *)HMACSHA1withKey:(NSString *)key forString:(NSString *)string
    {
       NSData *clearTextData = [string dataUsingEncoding:NSUTF8StringEncoding];
       NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
    
       uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0};
    
       CCHmacContext hmacContext;
       CCHmacInit(&hmacContext, kCCHmacAlgSHA1, keyData.bytes, keyData.length);
       CCHmacUpdate(&hmacContext, clearTextData.bytes, clearTextData.length);
       CCHmacFinal(&hmacContext, digest);
    
       return [NSData dataWithBytes:digest length:CC_SHA1_DIGEST_LENGTH];
    }
    
    //Source http://www.cocoadev.com/index.pl?BaseSixtyFour
    
    - (NSString *)base64forData:(NSData *)data
    {
        static const char encodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    
        if ([data length] == 0)
            return @"";
    
        char *characters = malloc((([data length] + 2) / 3) * 4);
        if (characters == NULL)
            return nil;
        NSUInteger length = 0;
    
        NSUInteger i = 0;
        while (i < [data length])
        {
            char buffer[3] = {0,0,0};
            short bufferLength = 0;
            while (bufferLength < 3 && i < [data length])
                buffer[bufferLength++] = ((char *)[data bytes])[i++];
    
            //  Encode the bytes in the buffer to four characters, including padding "=" characters if necessary.
            characters[length++] = encodingTable[(buffer[0] & 0xFC) >> 2];
            characters[length++] = encodingTable[((buffer[0] & 0x03) << 4) | ((buffer[1] & 0xF0) >> 4)];
            if (bufferLength > 1)
                characters[length++] = encodingTable[((buffer[1] & 0x0F) << 2) | ((buffer[2] & 0xC0) >> 6)];
            else characters[length++] = '=';
            if (bufferLength > 2)
                characters[length++] = encodingTable[buffer[2] & 0x3F];
            else characters[length++] = '=';    
        }
    
        return [[[NSString alloc] initWithBytesNoCopy:characters length:length encoding:NSASCIIStringEncoding freeWhenDone:YES] autorelease];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pulling my hair out on this one. I'm using the FlexSlider on a
I am pulling me hair out about this one. http://www.nettunes.co.za/build/contact.php I have an image
Pulling my hair out over this one. I have one wordpress install at /2009
I'm pulling my hair out on this. I do some manual deserialization using XmlReader
I'm really pulling my hair out on this one, it seems that I'm having
I'm pulling my hair out on this one. I am trying to implement a
I'm pulling my hair out over this one. I want to get all contents
I've been pulling my hair out over this one...and Im fairly sure its strait
I've come to the point of pulling my hair out over this one. I
I am pulling the hair out of my head trying to figure this one

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.