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 7174739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:07:18+00:00 2026-05-28T16:07:18+00:00

I’m using ASIHTTPRequest to upload a photo with PHP. The PHP side is proven

  • 0

I’m using ASIHTTPRequest to upload a photo with PHP. The PHP side is proven to work(I’m using it for android), and I’m trying to get the iOS component to work.

Here is my upload:

NSString *myurl = @"http://mydomain.tld/php/upload.php?casenum=";
    myurl = [myurl stringByAppendingFormat: casenumber];
    NSString *fixedURL = [myurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSString stringWithFormat:@"%@",fixedURL];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    NSData *imageData = UIImageJPEGRepresentation(image1.image, 90);
    [request setData:imageData withFileName:@"myphoto.jpg" andContentType:@"image/jpeg" forKey:@"file"];

    [request setCompletionBlock:^{
        NSString *responseString = [request responseString];
        NSLog(@"Response: %@", responseString);
    }];
    [request setFailedBlock:^{
        NSError *error = [request error];
        NSLog(@"Error: %@", error.localizedDescription);
    }];

    [request startAsynchronous];

Ive found this on the internet and when I run it, it fails with the error 2012-01-17 10:52:16.939 MyApp[30373:707] Error: NSInvalidArgumentException

From many of the documentation and examples I’ve found online, this should work, but it isn’t, as you can see with the exception. Any help at ironing out the kinks? If you need any other information, I’ll gladly post it.

  • 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-05-28T16:07:18+00:00Added an answer on May 28, 2026 at 4:07 pm

    There would appear to be a couple of errors in the way that you’re producing the NSURL. Firstly, it’s only the parameters that need escaping, not the whole URL, so

    NSString *myurl = @"http://mydomain.tld/php/upload.php?casenum=";
    myurl = [myurl stringByAppendingFormat: casenumber];
    NSString *fixedURL = [myurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    

    should be

    NSString *myurl = @"http://mydomain.tld/php/upload.php?casenum=";
    NSString *escapedCasenumber = [casenumber stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    myurl = [myurl stringByAppendingFormat:escapedCasenumber];
    

    Secondly, you’re then trying to assign an NSString to an NSURL, so

    NSURL *url = [NSString stringWithFormat:@"%@",fixedURL];
    

    should be

    NSURL *url = [NSURL urlWithString:myurl];
    

    Finally, the second argument passed to UIImageJPEGRepresentation should be a float value between 0.0 and 1.0, so I’m guessing

    NSData *imageData = UIImageJPEGRepresentation(image1.image, 90);
    

    should be

    NSData *imageData = UIImageJPEGRepresentation(image1.image, 0.9);
    

    If it still doesn’t work after these changes, then do as JosephH suggests and use the debugger to identify exactly which line is causing the exception

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

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.