1
我正試圖在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);
}
這確實是'一些'的代碼... – Julian
我現在已經粘貼了其餘的代碼。我希望它是可讀的。有沒有辦法處理這個問題? – user947185