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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:36:59+00:00 2026-05-27T07:36:59+00:00

I want to send iPhone image to server database. I wrote following code. I

  • 0

I want to send iPhone image to server database. I wrote following code. I am getting data mismatch exception and not able to resolve it. Could anyone please help me out.

Code on iPhone side:

- (void) uploadUserInfo:(NSString*)userId profilePic:(UIImage*)profilePic {

    __block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL: [NSURL URLWithString:[NSString stringWithFormat:@"%@/%d/uploadUserInfo?cultureDetect=false", dataUrl, currentAppID]]];

    [request setPostValue:userId forKey: @"userId"];
    // Upload an image
    [request addPostValue:@"pic.jpg" forKey:@"fileName"];
    NSData* imageData = UIImageJPEGRepresentation(profilePic, 1);
    [request setData:imageData withFileName:@"pic.jpg" andContentType:@"image/jpeg" forKey:@"profilePic"];

    [request setDelegate:self];
    [request setDidFinishSelector:@selector(uploadRequestFinished:)];
    [request setDidFailSelector:@selector(uploadRequestFailed:)];

    [queue addOperation: request];
    [queue go];

}

Code on ASP.NET MVC website Controller:

    public void uploadUserInfo(string userId, string fileName, byte[] profilePic)
    {
        int ID;
        if (int.TryParse(appId, out ID) && fileName != null && profilePic != null)
        {
            Image model = new Image();
            System.Drawing.Image image = System.Drawing.Image.FromStream(new System.IO.MemoryStream(profilePic));
            System.Drawing.Point maxSize = FileUtils.GetImageMaxSize(Image.ImageTypeEnum.TableCellImage);
            System.Drawing.Image thumb = ImageUtilities.GetFixedSizeImage(image, InterpolationMode.HighQualityBicubic, null, PixelFormat.Format32bppArgb, maxSize.X, maxSize.Y, false);
            byte[] resizedContent = ImageUtilities.GetBytesFromImage(thumb, ImageFormat.Png);
            model.AmendedDateTime = DateTime.Now;
            model.ApplicationId = ID;
            model.ImageType = Image.ImageTypeEnum.TableCellImage;
            string contentType = ImageUtilities.GetContentType(resizedContent);

            FileInfo f = new FileInfo(fileName);
            string name = f.Name.Substring(0, f.Name.Length - f.Extension.Length);
            string extension = f.Extension.Substring(1);

            BinaryFile file = new BinaryFile()
            {
                ContentType = contentType,
                FileName = name,
                FileExtension = extension
            };

            file.Data = resizedContent;
            model.BinaryFile = file;

            this.DataContext.Images.Table.InsertOnSubmit(model);

            ValidateAndSubmitChanges();
        }
        return;
    }

I have been getting following error before my method start executing. i.e. I guess MVC engine throwing exception directly when data type mismatched.

 [FormatException]: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. 
   at System.Convert.FromBase64String(String s)
   at System.Web.Mvc.ByteArrayModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
   at System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor)
   at System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__4()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I tried converting NSData to Byte but ASIHTTPRequest doesn’t allow to setData as Byte data type:

    NSUInteger len = [imageData length];
    Byte *byteData = (Byte*)malloc(len);
    memcpy(byteData, [imageData bytes], len);
    [request setData:byteData withFileName:@"pic.jpg" andContentType:@"image/jpeg" forKey:@"profilePic"];

Conversion to Base64 gives the same exception!

using ASIHTTPRequest inbuilt static method:

  NSData* imageData = UIImageJPEGRepresentation(profilePic, 1);
  [request setData:[ASIHTTPRequest base64forData:imageData] withFileName:@"pic.jpg" andContentType:@"image/jpeg" forKey:@"profilePic"];

using method given at this thread:

    NSData* imageData = UIImageJPEGRepresentation(profilePic, 1);
    [request setData:[NSString base64StringFromData:imageData length:[imageData length]]  withFileName:@"pic.jpg" andContentType:@"image/jpeg" forKey:@"profilePic"];
  • 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-27T07:36:59+00:00Added an answer on May 27, 2026 at 7:36 am

    This has annoyed me a lot! I just needed to replace Byte[] with HttpPostedFileBase which automatically handles posted files.

    iPhone code:

        - (void) uploadUserInfo:(NSString*)userId profilePic:(UIImage*)profilePic {
    
        __block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL: [NSURL URLWithString:[NSString stringWithFormat:@"%@/app/%d/phone/uploadUserInfo?cultureDetect=false", dataUrl, currentAppID]]];
    
        NSData* imageData = UIImageJPEGRepresentation(profilePic, 1);
        [request setData:imageData  withFileName:@"pic.jpg" andContentType:@"image/jpeg" forKey:@"imageFile"];
    
        [request setDelegate:self];
        [request setDidFinishSelector:@selector(uploadRequestFinished:)];
        [request setDidFailSelector:@selector(uploadRequestFailed:)];
    
        [queue addOperation: request];
        [queue go];
    }
    

    ASP.NET MVC Controller code:

    public void uploadUserInfo(HttpPostedFileBase imageFile)
    {
           // Process imageFile
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some image data (jpeg) I want to send from my iPhone app
I want to send post data from Iphone. I have to send a dictionary(K-V
I want to be able to send files from an iPhone app to a
I want to be able to send arbitrary messages from my iphone to the
I want to send data to server when user fill ups the from in
In iPhone App I want to send Image and Text together in single Email
I want to send an image to a web server running .Net which is
I want to send my gps data from my iphone/ipad using restful service, but
I want to send an email from within my iPhone application, primarily because i
Possible Duplicate: How to programmatically send SMS on the iPhone? I want to implement

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.