rest - Uploading to Amazon S3 Services from iPhone App -


I'm pulling my hair on this ... I use Asaiactiteepiariiiiist () wrapper library Amazon S3 storage. I am just able to connect properly and without any problem I am getting the list of buckets. My disappointment is with trying to upload (put and / or post) a new object (a picture) for an existing bucket I am following Amazon's document in the letter (at least I think I I am.) But nothing is working.

Please, before leaving the window, someone helps me, I do not want to wash my hands. :

L.

This is a basic example using PUT. Obviously, you should use the queue instead of a synchronous request in the real world.

If you change Amje header, then forget to update 'canonicalizedAmzHeaders' according to Amazon instructions

  #import "ASIHTTPRequest.h" #import & LT; CommonCrypto / CommonHMAC.h>. ... - (zero) testS3 {NSString * filePath = @ "/ path / to / file", NSString * contentType = @ "text / plain"; NSString * bucket = @ "mybucket"; NSString * path = @ "test"; NSString * secretAccessKey = "@Mary-Secret-Access Key", NSString * accesskey = @ "My-Access Key"; NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [DateFormatter setDateFormat: @ "EEE, MMM MM YYYY: mm: ss ZZZZ"]; NSString * date = [dateFormatter stringFromDate: [date of NSDT]]; Asaiactiteepiariveist * request = [[[Asaiactiteepiaraisisi Elokes] I NitWithURL: [NSURL URLWithString: [NSString stringWithFormat: @ "http: //%@.s3.amazonaws.com/%@", pail, path]]] autorelease]; [Request setPostBodyFilePath: filePath]; [Set Shouldstream PostDataForm Disk: Yes]; [Request Setup Method: @ "Pot"]; [Request addRequestHeader: @ "x-amz-acl" value: @ "private"]; [Request addRequestHeader: @ "content-type" value: contentType]; [Request addRequestHeader: @ "date" value: date]; NSSTING * CanonizedAzad's Headers = @ "X-AMS-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 base64for data: [HMACSHA1withKey: secretAccessKey forString: stringToSign]]; NSString * auth = [NSString stringWithFormat: @ "AWS% @:% @", accesskey, signature]; [Request RequestJoin RequestRequestHeader: @ "Authority" Value: auth]; [Start request]; NSLog (@ "% @", [Request Feedback String]); } // Source: http://stackoverflow.com/questions/476455/is-there-a-library-for-iphone-to-work-with-hmac-sha-1-encoding - :( HMACSHA1withKey (NSData *) NSString *) String for Key: (NSString *) String {NSData * clearTextData = [String Data Device Encoding: NSUTF8StringEncoding]; NSDTA * KeyData = [Key Data UDP encoding: NSUTF 8 string encoding]; Uint8_t digest [CC_SHA1_DIGEST_LENGTH] = {0}; CCHMACttex HMACenttex; CCHMACIIT (& amp; HMAC Context, KCHMACALGSHA1, Keydata, Bytes, Keydata Lamp); CCHMACEpad (& amp; HmACTNext, Clear TextData.bites, Clear TextData lamps); CCHMACifinal (and HMAC Contex, Digest); Return [NSDT Data Databases: 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; four * characters = mauloq ((([length of data] + 2) / 3) * 4); if (character == faucet) return zero; NSUI The length = 0; NSUInteger i = 0; while (I & lt; [length of data]) {four buffers [3] = {0,0,0}; small buffer length = 0; while (buffer lanment & lt; 3 & amp; amp; i & lt; [data length]) buffer [buffer lang ++] = ((four *) [data bytes]) [i ++]; // buffer encodes up to four characters in buffer Do, which requires padding "=" characters if the character [length ++] = encoding L [(buffer [0] and 0xFC)> gt; & gt; 2]; [length ++] = encoding enabled [(buffer [0] and 0x03) & lt; 4) | (Buffer [1] and 0xF0)> 4); if (buffer langle> 1) character [length ++] = encoding enabled [(buffer [1] and 0x0 f) & lt ; 2) | ((buffer [2] & 0xC0)>> 6)]; Other letters [length ++] = '='; if (buffer length> 2) letters [length + +] = Encoding enabled [Buffer [2] & amp; 0x3F]; Other characters [length ++] = '=';} Return [[NSString alloc] initWithBytesNoCopy: Characters Length: Length Encoding: NSASCIIStringEncoding freeWhenDone: Yes] autorelease ]; }  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -