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

  • Home
  • SEARCH
  • 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 6630279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:22:50+00:00 2026-05-25T22:22:50+00:00

I would like to extend the sample ios code called SimpleURLConnections. This sample code

  • 0

I would like to extend the sample ios code called SimpleURLConnections. This sample code can upload a file using HTTP POST. I have enabled my apache web server with a cgi script written in Perl to receive the HTTP POST that addresses the cgi script and successfully uploads the file. The extension I would like to make is to add a title or description of the uploaded file. I have tried to update the multipart form data in the sample code and a corresponding change to my cgi script to transfer this description, but it is failing. The cgi script cannot read in the description using the cgi.pm method called param(). I’m hoping someone can help. Here are the details:

The multipart form data BEFORE my modification looks like the following (NOTE: the SimpleURLConnections routine inserts the image file between the Content-Type and the 2nd boundary on the fly):

--Boundary-D4AFFBA9-AD92-4697-9184-7BDA128C3B97
Content-Disposition: form-data; name="fileContents"; filename="1234567/TestImage1.png"
Content-Type: image/png

--Boundary-D4AFFBA9-AD92-4697-9184-7BDA128C3B97
Content-Disposition: form-data; name="uploadButton"

Upload File
--Boundary-D4AFFBA9-AD92-4697-9184-7BDA128C3B97--

The multipart form data AFTER my modification looks like the following:

--Boundary-D4AFFBA9-AD92-4697-9184-7BDA128C3B97
Content-Disposition: form-data; name="Title"; title="Hello World"
Content-Type: text/plain
--Boundary-D4AFFBA9-AD92-4697-9184-7BDA128C3B97
Content-Disposition: form-data; name="fileContents"; filename="1234567/TestImage1.png"
Content-Type: image/png


--Boundary-D4AFFBA9-AD92-4697-9184-7BDA128C3B97
Content-Disposition: form-data; name="titleButton"
my Title

--Boundary-D4AFFBA9-AD92-4697-9184-7BDA128C3B97
Content-Disposition: form-data; name="uploadButton"

Upload File
--Boundary-D4AFFBA9-AD92-4697-9184-7BDA128C3B97--

My cgi script looks like the following:

#!/usr/bin/perl -wT
use strict;use CGI;
use CGI::Carp qw ( fatalsToBrowser );
use File::Basename;

my $upload_dir = "/Library/WebServer/Documents/upload";

my $query = new CGI;

my $title = $query->param("Title");

#if (!$title) {
#    die "the title is $title. $!";
#}

if ( !$filename ) {
        print $query->header ( );
        die "There was a problem uploading your photo (try a smaller file). : $!";
        exit;
}
...

open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
while ( <$upload_filehandle> ) {
    print UPLOADFILE;
}

close UPLOADFILE;

This code works fine and the uploaded file gets written to the upload_dir.

But, if I uncomment that little block of code:

if (!$title) {
    die "the title is $title. $!";
}

the script dies with an error that indicates that $title has no value:

[Tue Sep 27 17:09:17 2011] [error] [client 10.0.1.2] [Tue Sep 27 17:09:17 2011] upload.cgi: Use of uninitialized value $title in print at /Library/WebServer/CGI-Executables/upload.cgi line 79.

So, is the problem with my multipart form data, the cgi script, or is it not possible to pass this data in the multipart form data? Is there an alternate way?

Thanks

Ok, after getting help from @AFresh1, I found the problem. The problem was in the details of how the multipart form data was created. First I will show the wrong way.

NSString *title = @"Hello World";
bodySuffixStr = [NSString stringWithFormat:     // create the footer for the POST message
            @
            "\r\n"
            "--%@\r\n"
            "Content-Disposition: form-data; name=\"titleButton\"\r\n"
            "%@\r\n\r\n"
            "--%@\r\n"
            "Content-Disposition: form-data; name=\"uploadButton\"\r\n"
            "\r\n"
            "Upload File\r\n"
            "--%@--\r\n" 
            "\r\n",
            boundaryStr,
            title,
            boundaryStr, 
            boundaryStr
        ];

Now the correct way (a very subtle change in the 7th line – moved the CR/LF):

NSString *title = @"Hello World";
bodySuffixStr = [NSString stringWithFormat:     // create the footer for the POST message
            @
            "\r\n"
            "--%@\r\n"
            "Content-Disposition: form-data; name=\"titleButton\"\r\n"
            "\r\n%@\r\n"
            "--%@\r\n"
            "Content-Disposition: form-data; name=\"uploadButton\"\r\n"
            "\r\n"
            "Upload File\r\n"
            "--%@--\r\n" 
            "\r\n",
            boundaryStr,
            title,
            boundaryStr, 
            boundaryStr
        ];
  • 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-25T22:22:51+00:00Added an answer on May 25, 2026 at 10:22 pm

    I believe the content goes in the space after the header
    and before the next boundary not in a title attribute. The part header being everything after the boundary and before the blank line.

    If you are want to get “Hello World” into $title using $query->param('Title') I think you will need something more like this (note that Content-type defaults to text/plain):

    --Boundary-D4AFFBA9-AD92-4697-9184-7BDA128C3B97
    Content-Disposition: form-data; name="Title"
    
    Hello World
    --Boundary-D4AFFBA9-AD92-4697-9184-7BDA128C3B97
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I extend a builtin class in python? I would like to add
I would like to extend the Queue.PriorityQueue described here: http://docs.python.org/library/queue.html#Queue.PriorityQueue The queue will hold
I would like to extend a kd-tree (2D) class to be able to remove
I would like to create extend a Java Swing application to have a look
I'm trying to extend my ActiveRecord class with some dynamic methods. I would like
Would like to get a list of advantages and disadvantages of using Stored Procedures.
I have an ASPX page (with VB Codebehind). I would like to extend the
Another question asked about attributes, but I would like to extend the question to
I am using multiple asynchronous air.URLLoader objects, and would like the events fired to
I am making a top-down platformer game using sprites. I would like to add

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.