2

Windows azure SDK-ios 仅适用于 mobileService,我想将一些内容上传到 iOS 应用程序中的存储。

有任何核心库可以做到这一点吗?

4

2 回答 2

2

试试这个

UIImage *img = self.imageItem.image;
    NSData *imageData = UIImageJPEGRepresentation(img, 0.5);

    NSMutableURLRequest* theRequest = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: {replace with the storage url you are uploading to}  ] ];
    [theRequest setHTTPMethod: @"PUT"];
    [theRequest setHTTPBody: imageData];
    [theRequest setValue:@"image/PNG" forHTTPHeaderField:@"Content-Type"];
    [theRequest setValue:@"BlockBlob"  forHTTPHeaderField:@"x-ms-blob-type"];
    [theRequest setValue:[NSString stringWithFormat:@"%d", [imageData length]] forHTTPHeaderField:@"Content-Length"];
    NSData *response;
    NSError *WSerror;
    NSURLResponse *WSresponse;
    NSString *responseString;
    response = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&WSresponse error:&WSerror];
    responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding] ;
于 2013-06-01T06:09:33.863 回答
2

看看这个演练:http ://chrisrisner.com/Mobile-Services-and-Windows-Azure-Storage 。它详细介绍了如何使用移动服务生成安全访问签名,您可以将其交回 iOS 应用程序以用于上传到 blob 存储。这可以防止您需要在客户端应用程序中保留存储帐户名称和密钥。

于 2013-06-01T22:45:59.480 回答