上传图片时出现 cocoa 3840 错误?
while uploading image getting cocoa 3840 error?
我在这里尝试将图像发送到服务器端,但它给我错误
if(picking)
{
NSLog(@"entering in to image side");
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"content-Disposition:form-data;name=\"pic\"\r\n\r\n filename=imageName.jpg\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:picking]];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
}
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[body length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
dispatch_async(dispatch_get_main_queue(),^{
if([data length]>0 && connectionError==nil)
{
NSError *error;
NSMutableDictionary *jsonResponse=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
if(error){
[Utitlity alertFunction:@"Warning" message:[error localizedDescription]];
}
else
{
[self requestComplete:jsonResponse];
}
}
此图片出现在注册屏幕中,如果我没有select注册屏幕中的图片意味着,客户注册将获得 success.while select 图片 cocoa 3048 错误。
问题出在您的以下陈述中。根据 Apple 文档 NSJSONReadingMutableContainers
选项应该用于数组和字典。请尝试 NSJSONReadingAllowFragments
.
NSMutableDictionary *jsonResponse=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
Constants NSJSONReadingMutableContainers Specifies that arrays and
dictionaries are created as mutable objects.
Available in iOS 5.0 and later. NSJSONReadingMutableLeaves Specifies
that leaf strings in the JSON object graph are created as instances of
NSMutableString.
Available in iOS 5.0 and later. NSJSONReadingAllowFragments Specifies
that the parser should allow top-level objects that are not an
instance of NSArray or NSDictionary.
Available in iOS 5.0 and later.
我在这里尝试将图像发送到服务器端,但它给我错误
if(picking)
{
NSLog(@"entering in to image side");
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"content-Disposition:form-data;name=\"pic\"\r\n\r\n filename=imageName.jpg\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:picking]];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
}
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[body length]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
dispatch_async(dispatch_get_main_queue(),^{
if([data length]>0 && connectionError==nil)
{
NSError *error;
NSMutableDictionary *jsonResponse=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
if(error){
[Utitlity alertFunction:@"Warning" message:[error localizedDescription]];
}
else
{
[self requestComplete:jsonResponse];
}
}
此图片出现在注册屏幕中,如果我没有select注册屏幕中的图片意味着,客户注册将获得 success.while select 图片 cocoa 3048 错误。
问题出在您的以下陈述中。根据 Apple 文档 NSJSONReadingMutableContainers
选项应该用于数组和字典。请尝试 NSJSONReadingAllowFragments
.
NSMutableDictionary *jsonResponse=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
Constants NSJSONReadingMutableContainers Specifies that arrays and dictionaries are created as mutable objects.
Available in iOS 5.0 and later. NSJSONReadingMutableLeaves Specifies that leaf strings in the JSON object graph are created as instances of NSMutableString.
Available in iOS 5.0 and later. NSJSONReadingAllowFragments Specifies that the parser should allow top-level objects that are not an instance of NSArray or NSDictionary.
Available in iOS 5.0 and later.