Objective c 当我将一个文件发送到服务器时,如何处理它被分成几个部分?

Objective c 当我将一个文件发送到服务器时,如何处理它被分成几个部分?,objective-c,Objective C,我正在尝试用Objective C编写代码,它应该向服务器发送一个JPEG文件。问题是文件被分成几个部分,只有第一部分到达那里。有办法解决这个问题吗 下面是一些代码: int j; for (j = 0; j < 5; j++) { // Read in data from appropriate signature file NSMutableString *imagePath = [folder_path_2 mutableCopy]; [im

我正在尝试用Objective C编写代码,它应该向服务器发送一个JPEG文件。问题是文件被分成几个部分,只有第一部分到达那里。有办法解决这个问题吗

下面是一些代码:

int j;
for (j = 0; j < 5; j++) {        
    // Read in data from appropriate signature file
    NSMutableString *imagePath = [folder_path_2 mutableCopy];
    [imagePath appendString:fn[j]];
    [imagePath appendString:@".jpeg"];
    NSLog(imagePath);

    NSData *imageData = nil;
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagePath];
    if (fileExists) {
        imageData = [[NSData alloc] initWithContentsOfFile:imagePath];
    } else {
        NSLog(@"JPEG image file does not exist.");
    }

    request = [[[NSMutableURLRequest alloc] init] autorelease];
    [request setURL:[NSURL URLWithString:urlStr]];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"image/jpeg" forHTTPHeaderField:@"Accept"];
    [request setValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];

    int len = (int)[imageData length];
    length_str  = [NSString stringWithFormat: @"%d", len];
    [request setValue:length_str forHTTPHeaderField:@"Content-Length"];
    postBody = [NSMutableData data];
    [postBody appendData:[NSData dataWithData:imageData]];

    [request setHTTPBody:postBody];

    // Make connection to the Internet
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil
                                                       error:nil];
    NSString *returnString = (NSString*)[[NSString alloc] initWithData:returnData
                                                          encoding:NSUTF8StringEncoding];
    NSLog(returnString);
}
intj;
对于(j=0;j<5;j++){
//从相应的签名文件读入数据
NSMutableString*imagePath=[folder_path_2 mutableCopy];
[imagePath appendString:fn[j]];
[imagePath appendString:@.jpeg];
NSLog(imagePath);
NSData*图像数据=零;
BOOL fileExists=[[NSFileManager defaultManager]fileExistsAtPath:imagePath];
如果(文件存在){
imageData=[[NSData alloc]initWithContentsOfFile:imagePath];
}否则{
NSLog(@“JPEG图像文件不存在。”);
}
请求=[[NSMutableURLRequest alloc]init]autorelease];
[请求设置URL:[NSURL URLWithString:urlStr]];
[请求设置HttpMethod:@“POST”];
[请求设置值:@“图像/jpeg”用于HttpHeaderField:@“接受”];
[请求设置值:@“图像/jpeg”用于HttpHeaderField:@“内容类型”];
int len=(int)[图像数据长度];
长度_str=[NSString stringWithFormat:@“%d”,len];
[请求设置值:长度\u str for HttpHeaderField:@“内容长度”];
postBody=[NSMutableData];
[postBody appendData:[NSData dataWithData:imageData]];
[请求setHTTPBody:postBody];
//上网
NSData*returnData=[NSURLConnection sendSynchronousRequest:request returningResponse:nil
错误:无];
NSString*returnString=(NSString*)[[NSString alloc]initWithData:returnData
编码:NSUTF8StringEncoding];
NSLog(返回字符串);
}

您试图发送的jpeg文件有多大?

这确实是代码的“部分”…我现在已粘贴了其余的代码。我希望它是可读的。有办法解决这个问题吗?