It looks like you're new here. If you want to get involved, click one of these buttons!
// Place image in ImageView
self.vImage.image = image;
tongo.time = 13;
// Upload Image to server
NSData *imageDataUpload = UIImageJPEGRepresentation(vImage.image, 90);
NSString *urlString = @\"http://website/upload.php\";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@\"POST\"];
NSString *boundary = [NSString stringWithString:@\"---------------------------14737809831466499882746641449\"];
NSString *contentType = [NSString stringWithFormat:@\"multipart/form-data; boundary=%@\", boundary];
[request addValue:contentType forHTTPHeaderField:@\"Content-Type\"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@\"\r\n--%@\r\n\", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@\"Content-Disposition: form-data; name=\\"userfile\\"; filename=\\".png\\"\r\n\"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@\"Content-Type: application/octet-stream\r\n\r\n\"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageDataUpload]];
[body appendData:[[NSString stringWithFormat:@\"\r\n--%@--\r\n\", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(returnString);
if (returnString) {
self.imageLabel.text = @\"Uploaded\";
}
Replies
The easiest way to solve that is to separate the uploading in a different method. For example:
-(void) uploadFile:(NSString*) path ;
Then, in your actual code, you write:
[self performSelector:@selector(uploadFile:) withObject:path afterDelay:0.0];
then the method ends, control returns to the main loop, the user interface does the modifications and immediately the new uploadFile: method is invoked.
Gabriel
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeYou are sending your POST request synchronously. That freezes everything until the post is complete. UI changes like installing an image into an image view don't take effect until your code returns, which doesn't happen because of the synchronous POST.
Rewrite your code to do the post asynchronously. You should use the NSURLConnection sendAsynchronousRequest:queue:completionHandler instead of using sendSynchronousRequest.
That code might look like this:
Disclaimer: I still struggle with the syntax for blocks that take parameters, so the syntax above may not be correct.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome