Objective c 如何将UIImage从iOS上载到Azure存储
我尝试通过MVC4WebAPI将图像上传到Azure存储。但是服务器端总是返回: “Base-64字符数组或字符串的长度无效。” 以下是Objective-C代码:Objective c 如何将UIImage从iOS上载到Azure存储,objective-c,azure-storage,Objective C,Azure Storage,我尝试通过MVC4WebAPI将图像上传到Azure存储。但是服务器端总是返回: “Base-64字符数组或字符串的长度无效。” 以下是Objective-C代码: - (IBAction)btnUploadReceipt:(id)sender { UIImage *img = self.imgReceipt.image; NSData *dataObj = UIImagePNGRepresentation(img); NSString *fff = [dataObj b
- (IBAction)btnUploadReceipt:(id)sender {
UIImage *img = self.imgReceipt.image;
NSData *dataObj = UIImagePNGRepresentation(img);
NSString *fff = [dataObj base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
//NSString *ddd = [self base64EncodeString:imgData];
//NSString *ddd = [dataObj base64EncodedString];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/api/upload/UploadAzure",baseUrl]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"Post"];
NSString *jsonData = [NSString stringWithFormat:@"FileName=%@&FileData=%@&FolderName=%@&UserName=%@&Point=%@&DateTime=%@&MerchantName=%@&OutletID=%@",fileName,fff,imgFolder,userName,@"3",dateTime,_mName,_mOutletID];
[request setHTTPBody:[jsonData dataUsingEncoding:NSUTF8StringEncoding]];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response,
NSData *data, NSError *connectionError)
{
if (data.length > 0 && connectionError == nil)
{
NSString * json =[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",json);
if ([json isEqualToString:@"\"True\""]) {
NSLog(@"%@",@"Success Add Photo");
//[self dismissViewControllerAnimated:YES completion:nil];
//[[self navigationController]popViewControllerAnimated:YES];
}
else
{
UIAlertView *messageAlert = [[UIAlertView alloc]initWithTitle:@"Connection Error" message:@"Please Check Internet Setting" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[messageAlert show];
}
}
else
{
UIAlertView *messageAlert = [[UIAlertView alloc]initWithTitle:@"Connection Error" message:@"Please Check Internet Setting" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[messageAlert show];
}
}];
}
- (NSString *)base64String2 {
UIImage *img = self.imgReceipt.image;
NSData * data = [UIImagePNGRepresentation(img) base64EncodedDataWithOptions:NSDataBase64Encoding64CharacterLineLength];
return [NSString stringWithUTF8String:[data bytes]];
}
有人面临这种问题吗?您是否尝试过使用?应该能够对您的场景提供帮助