Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8485411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:38:13+00:00 2026-06-10T20:38:13+00:00

I am sending a file to the server. Like in this tutorial: http://zcentric.com/2008/08/29/post-a-uiimage-to-the-web/#comment-8145 –

  • 0

I am sending a file to the server. Like in this tutorial: http://zcentric.com/2008/08/29/post-a-uiimage-to-the-web/#comment-8145

- (IBAction)uploadImage {
/*
 turning the image into a NSData object
 getting the image back out of the UIImageView
 setting the quality to 90
*/
NSData *imageData = UIImageJPEGRepresentation(image.image, 90);
// setting up the URL to post to
NSString *urlString = @"http://iphone.zcentric.com/test-upload.php";

// setting up the request object now
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

/*
 add some header info now
 we always need a boundary when we post a file
 also we need to set the content type

 You might want to generate a random boundary.. this is just the same 
 as my output from wireshark on a valid html post
*/
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

/*
 now lets create the body of the post
*/
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"rn--%@rn",boundary] dataUsingEncoding:NSUTF8StringEncoding]];    
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name="userfile"; filename="ipodfile.jpg"rn"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-streamrnrn"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"rn--%@--rn",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the reqeust
[request setHTTPBody:body];

// now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(returnString);
}

And from the server side:

$uploaddir = './uploads/';
$file = basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $file;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "http://iphone.zcentric.com/uploads/{$file}";
}

Anyone could please answer me:

  • Any way to check if the file was uploaded completely or there is an error and send the result of the process from the server to the app.
  • In case there is an interruption (like pressing the home button or a phone call or the network has fallen) will the app finish the uploading when the app is active again.

Basically I have to update a database when the file is uploaded but I have to be sure there were no errors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:38:15+00:00Added an answer on June 10, 2026 at 8:38 pm

    As long as your server responds with URL of uploaded file (which means it was uploaded successfully), you can check returnString for being non-empty and containing meaningful URL and returned codes & errors.

    NSHTTPURLResponse* response;
    NSError* err;
    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
    NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    if (err) {
        //Network error happened (DOESN'T mean HTTP error code)
        NSLog(@"Error: %@", err);
        return;
    }
    if ([response statusCode] != 200) { 
        //Server returned HTTP error code
        NSLog(@"Error: Server returned non 200 code");
        return;
    }
    if (![NSURL urlWithString:returnString]) { 
        //URL is not valid
        NSLog(@"File URL returned from server is not valid");
        return;
    }
    //File uploaded
    NSLog(@"File uploaded successfully");
    

    This examples assumes you’re using ARC in your project (so no releases).

    To correctly handle application suspending, take a look at background tasks. You can make background task from your file upload code and it should continue uploading if application is moved to background.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that has images with urls like this: http://mysite.com/image1.jpg My server
im making file transfer (Server-Client) TCP i've already looked for same questions like this
I am sending post request from android to the url using httpclient like this
I have a client and server, client sending file to server. When i transfer
I am sending an audio file with extension .m4a on the server using ftp
I am using this for sending file to user header('Content-type: application/zip'); header('Content-Length: ' .
I'm trying to print an EPL file I've written. I'm sending the file like
I sending ajax request from a jQuery file like below, which expects response in
I am sending file from client to server using TCP. To mark the end
Currently, the client is sending messages like this: Public Function checkMD5(ByVal userID As Integer,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.