Hi All
I am using an API to upload a file to the server How can I update the progress indicator on file uploading with showing proper percentage of uploaded data?
Code which I am using for file upload
Please guide me on how should I show the progress indicator while uploading the file
Thanks
Monaj
I am using an API to upload a file to the server How can I update the progress indicator on file uploading with showing proper percentage of uploaded data?
Code which I am using for file upload
Code:
NSString *tempMsg,*stringBoundary,*contentType,*returnResult;
NSURL *cgiUrl ;
NSMutableURLRequest *postRequest;
NSError *error;
NSData *searchData;
NSHTTPURLResponse *response;
NSMutableData *postBody;
NSString *temp1,*attachedFile=@"",*originalAttachedFile=@"";
temp1=[[[attachedfileArray objectAtIndex:0] objectForKey:@"fileName"] lastPathComponent];
if([originalAttachedFile isEqualToString:@""]){
originalAttachedFile=temp1;
}else {
originalAttachedFile=[NSString stringWithFormat:@"%@,%@",originalAttachedFile,temp1];
}
NSRange rangeForDot=[temp1 rangeOfString:@"."];
temp1=[temp1 substringFromIndex:rangeForDot.location];
cgiUrl = [NSURL URLWithString:@"https://www.keysoftwareservices.com/API/rtcs_API.php"];
postRequest = [NSMutableURLRequest requestWithURL:cgiUrl];
[postRequest setHTTPMethod:@"POST"];
stringBoundary = [NSString stringWithString:@"0000RCSIMGUploadxxxxxx"];
contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", stringBoundary];
[postRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"\r\n\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"code\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:ans] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"action\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"uploadfile"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"path\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"/API/attachments/"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", [[[attachedfileArray objectAtIndex:l] objectForKey:@"fileName"] lastPathComponent]] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Type: image/%@\r\n\r\n",temp1] dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"Image type in post method.... %@",[NSString stringWithFormat:@"Content-Type: image/%@\r\n\r\n",temp1]);
[postBody appendData:[NSData dataWithContentsOfFile:[[attachedfileArray objectAtIndex:l] objectForKey:@"fileName"]]];
[postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postRequest setHTTPBody:postBody];
searchData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];
if([error code]==0){
}else {
NSBeginAlertSheet(@"Fail to attach file !",@"Ok",nil,nil,msgWindow,self,@selector(sheetDidEndShouldDelete4:returnCode4:contextInfo4:),NULL,msgWindow,@"Please check internet connnection");
return;
}
NSString* imageName;
imageName = [[NSString alloc] initWithData:searchData encoding:NSASCIIStringEncoding];
NSLog(@"retrun Result of Upload Photo.. %@",imageName);
Please guide me on how should I show the progress indicator while uploading the file
Thanks
Monaj