views:

474

answers:

1

I'm trying to use ASIFormDataRequest to send a photo image from my iPhone app to my server.

When I do so, the server sends back an error message saying, "must be an image file," implying that there is something wrong with the formatting of my image. (Of course, that might not be the problem...but it's a good place to start.) I know there's no "problem," per se, on the server, because a previous approach I used (non-ASIHTTPRequest-based) worked fine. Here's my iPhone code:

        ASIFormDataRequest* request = [ASIFormDataRequest requestWithURL: 
[NSURL URLWithString:photoUploadURLString]]; 
        request.username = self.username; 
        request.password = self.password; 
        [request setPostValue:self.place.placeId forKey:@"place_id"]; 
        NSData* jpegImageData = UIImageJPEGRepresentation(self.photo, 
PHOTO_JPEG_QUALITY); 
        NSString* filename = [NSString stringWithFormat:@"snapshot_%@_ 
%d.jpg", self.place.placeId, rand()]; 
        [request setData:jpegImageData withFileName:filename 
andContentType:@"image/jpeg" forKey:@"snapshot[image]"]; 
        request.uploadProgressDelegate = self.progressView; 
        [request startSynchronous]; 

Anyone see anything wrong with this? (I'm fairly new to this stuff, so there could be something obvious I'm missing.)

Thanks very much.

A: 

Hello Greg, Have you ever try addData instead of setData, It worked on my solution.

[request addData:jpegImageData withFileName: filename andContentType:@"image/jpeg" forKey:@"photos"];

Edit: By the way, which server side are you using ?

Your problem might be inside of the your key forKey:@"snapshot[image]"] try to dummy variable key like forKey:@"mysnapshot"]

Hope this helps

fyasar
Hi, fayasar—I'm actually at an entirely different company now, and I'm not sure how I ultimately fixed this problem! But the solutions you recommended: using addData, and using a key similar to snapshot[image], sounds right. Thanks for your help.
Greg Maletic
you are welcome, good luck for new company
fyasar