1

我想使用帐户密钥和帐户名将文件上传到窗口 Azure 存储。任何人都可以帮助我在目标 c 中实现这一目标。

我试过代码

NSString *urlString = :@"https://myaccount.blob.core.windows.net/coretest";

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"0xLhTaLbOkNdArZ"];

//Reading the file
NSString *filePath = @"/Users/rcj/Documents/Xcode.rtf";
NSLog(@"file Path to upload: %@",filePath);
NSData *myData = [NSData dataWithContentsOfFile:filePath];

NSMutableData *body = [NSMutableData data];

[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"Xcode.rtf\"\r\n"]      dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:myData];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];


NSDate *now = [[NSDate alloc] init];
NSString *dateString = [self rfc1123String:now];
NSString *AZURE_ACCOUNT_NAME = @"myaccount";
NSString *password = @"xxxxxxxxxxxxxxxxxxxxxxxxxxx==";

[request addValue:[NSString stringWithFormat:@"SharedKey %@:%@",AZURE_ACCOUNT_NAME, password] forHTTPHeaderField:@"Authorization"];

[request addValue:dateString forHTTPHeaderField:@"x-ms-date"];

[request addValue:@"application/atom+xml, application/xml"forHTTPHeaderField:@"Accept"];

[request addValue:@"UTF-8" forHTTPHeaderField:@"Accept-Charset"];

[request setHTTPBody:body]; 

NSLog(@"Headers: %@", [request allHTTPHeaderFields]);

NSLog(@"URL: %@", [[request URL] absoluteString]);
connection =[[NSURLConnection alloc] initWithRequest:request delegate:self];

if(connection) {
    receivedData = [[NSMutableData data] retain];
}

else {
       // Inform the user that the con
 }

感谢 RCJ

4

1 回答 1

0

我刚刚偶然发现了这个https://github.com/WindowsAzure/azure-mobile-services#readme,您可以在其中下载适用于 Azure beta 的 iOS SDK

于 2013-05-03T13:18:47.810 回答