Image 在iOS 7上图像上载失败

Image 在iOS 7上图像上载失败,image,ios7,upload,server,Image,Ios7,Upload,Server,我有一种方法可以将图像上传到服务器。 它可以在iOS 8上上载图像,但无法在iOS 7上上载图像。 图像是由相机拍摄的,否则我不会调整或编辑它 这是我的密码: NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; //Set Params [request setHTTPShouldHandleCookies:NO]; [request setTimeoutInterval:60]; [request setHTT

我有一种方法可以将图像上传到服务器。 它可以在iOS 8上上载图像,但无法在iOS 7上上载图像。 图像是由相机拍摄的,否则我不会调整或编辑它

这是我的密码:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

//Set Params
[request setHTTPShouldHandleCookies:NO];
[request setTimeoutInterval:60];
[request setHTTPMethod:@"POST"];

//Create boundary, it can be anything
NSString *boundary = @"AaB03xChuTieuDaDuyen";   

//Set Content-Type in HTTP header
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:contentType forHTTPHeaderField: @"Content-Type"];

//POST body
NSMutableData *body = [NSMutableData data];

//Populate a dictionary with all the regular values you would like to send.
NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setValue:[Utilities getTokenMD5] forKey:@"token"];
[parameters setValue:idKH forKey:@"idKH"];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

//Add params (all params are strings)
for (NSString *param in parameters) {
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", param] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"%@\r\n", [parameters objectForKey:param]] dataUsingEncoding:NSUTF8StringEncoding]];
}
NSString *FileParamConstant = @"CHUTIEUIMAGE";
NSData *imageData = UIImageJPEGRepresentation(imageOrinal , 0.5);
UIImage * imagetest = [UIImage imageWithData:imageData];

//Assuming data is not nil we add this to the multipart form
if (imageData)
{
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"image.jpg\"\r\n", FileParamConstant] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Type:image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:imageData];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
}

//Close off the request with the boundary
//[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

//Setting the body of the post to the request
[request setHTTPBody:body];

//Set URL
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[userDefaults objectForKey:@"urlserver"],ServerApiSendImage]]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc]initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
//    operation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/xhtml+xml"];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    [self stopLoading];
    NSLog(@"send Images response obj =%@",responseObject);
    [self sendImageRequestDidSuccess : responseObject];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    [self stopLoading];
    NSLog(@"error : %@",[error localizedDescription]);
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""
                                                        message:@"no connect"
                                                       delegate:nil
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];
    [alertView show];
}];
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, NSInteger totalBytesRead, NSInteger totalBytesExpectedToRead) {

    //Bytes received - saved bytesRead variable to NSUserDefaults
    NSLog(@"Camera Send Image Down load = %lld",(long long)totalBytesRead);
}];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {

    //Bytes sent - saved bytesWritten variable to NSUserDefaults
    NSLog(@"Camera Send Image Up load = %lld",(long long)totalBytesWritten);
}];
[operation start];

请参考此链接,它可以上载到服务器,但服务器响应错误图像格式谢谢您的帮助。这是服务器的故障。