0

I am using POST as discussed here to upload an image and some parameters to a server. On the server side i am using a stream to accept the image data but as its my first time I seem to be doing something wrong. Can someone point me to the right direction.

EDIT: Using the same code on client side(iPhone) as described in the link above. and my server code is something like this. Using a stored procedure to insert into the DB but i am not sure if the POST even reaches the method.

public void PublishIncident(string latd,string longt,string description, string picdatetime,            Stream data)
{ 
 latd = latd.Replace("-", ".");
 longt = longt.Replace("-", ".");

 string sImageName = string.Empty;
 DatabaseHelper dalInstance = new DatabaseHelper(sConnStr);
 try
 {
  dalInstance.AddParameter("pDescription", description);
  dalInstance.AddParameter("oImageName", "", ParameterDirection.Output);
  dalInstance.ExecuteNonQuery("rt_InsertIncident", CommandType.StoredProcedure);
  sImageName = Convert.ToString(dalInstance.Command.Parameters[4].Value);

  _streamToFile(sImageName, longt, description, picdatetime, data);
 }
 catch (Exception excp)
 {
   dalInstance.Dispose();
   throw excp;

 }
 finally
 {
     dalInstance.Dispose();
 }
 }

When i run it from the iphone i get a page not found response.

Community
  • 1
  • 1
B K
  • 1,554
  • 3
  • 19
  • 40
  • We're going to need a lot more detail before this can be answered: code, results, errors etc. – Paul Sasik Oct 22 '11 at 18:04
  • Since I am appending the image in the body of my request, is creating a stream the right way to go about this? – B K Oct 22 '11 at 18:43

1 Answers1

0

I went ahead and used the ASHIT framework and the thing worked like a charm. Just download the framework and code to actually upload image and parameters is as simple as -

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:urlURL]; // url to hit + parameters
[request setRequestMethod:@"POST"];

[request appendPostData:imageData]; // image as data
[request startSynchronous];
NSError *error = [request error];

if (error) {
    NSLog(@"error = %@", error);                
}
else
{
    // success
}
B K
  • 1,554
  • 3
  • 19
  • 40