upload image from iPhone application

后端 未结 1 1369
栀梦
栀梦 2021-01-01 07:08

i am trying to upload a image to server from iPhone application

PHP code for upload image is following

if(isset($_POST[\'insertImage\']))
{                   


        
相关标签:
1条回答
  • 2021-01-01 07:57

    You wrote the server code to only accept data with certain specified content types, but then you never added the content type to your data. Simply emit the correct content type for your image data:

    // Emit the content type here as well
    [postBody appendData:[[NSString stringWithFormat:@"--%@\r\n",stringBoundary] dataUsingEncoding:NSASCIIStringEncoding]];
    [postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"imageFile\"; filename=\"myimagefile.png\"\r\nContent-Type: image/png\r\n\r\n"] dataUsingEncoding:NSASCIIStringEncoding]];
    
    [postBody appendData:[NSData dataWithData:userImageData]];
    [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",stringBoundary] dataUsingEncoding:NSASCIIStringEncoding]];
    

    The error is actually coming back from your own server response, so simply following the flow of control on your server code gives you the cause.

    0 讨论(0)
提交回复
热议问题