2016-08-09 6 views
0
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> 
<html><head> 
<title>500 Internal Server Error</title> 
</head><body> 
<h1>Internal Server Error</h1> 
<p>The server encountered an internal error or 
misconfiguration and was unable to complete 
your request.</p> 
<p>Please contact the server administrator, 
[email protected] and inform them of the time the error occurred, 
and anything you might have done that may have 
caused the error.</p> 
<p>More information about this error may be available 
in the server error log.</p> 
<p>Additionally, a 500 Internal Server Error 
error was encountered while trying to use an ErrorDocument to handle the request.</p> 
<hr> 
<address>Apache Server at domain.com Port 80</address> 
</body></html> 

iOS開発者がPHPサーバに画像を送信しようとしました。しかし、彼らは上記のようなエラーを受けていますiOSデバイスからphpサーバに画像をアップロード中にエラーが発生しましたか?(500内部サーバエラー)

どうすればこの問題を解決できますか?

iOSコード問題またはPHP側の問題ですか?郵便配達員による

私がチェック: enter image description here

このURLを使用することによって、彼らは私に複数の画像を送信しているが、それは、単一の画像であれば、それは正常に動作しますが、それは働いていない複数の画像送信しようとしています:https://charangiri.wordpress.com/2014/09/22/how-to-upload-multiple-image-to-server/

+0

両側にある可能性があります。使用しているAPI URLが正しいことを確認してください。まず作成したAPIがあなた自身でPostmanでチェックしたり、最後にカールリクエストを使って確認したりします。サーバー上に画像をアップロードすることができれば、あなたのAPIは完璧です。 iOS開発者は間違いを犯しています。 – Jassi

+0

私はPOSTMANのスクリーンショットを投稿しました。一度確認してください: –

+0

このURLを使用すると、複数の画像を送信していますが、1枚の画像であればうまくいきますが、複数の画像を送信しようとしている場合は、https://charangiri.wordpress.com/2014/09/ 22/how-to-upload-multiple-image-to-server/ –

答えて

1

にあなたを下記のこの機能を使用して複数の画像をサーバにアップロードすることができます。私が使ったimagesarray変数は、UIImageオブジェクトを格納することです。必要に応じて変更することができます。

- (void)uploadImagesToServer{ 
//create request 
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 

//Set Params 
[request setHTTPShouldHandleCookies:NO]; 
[request setTimeoutInterval:60]; 
[request setHTTPMethod:@"POST"]; 

//Create boundary, it can be anything 
NSString *boundary = @"------friendlyWagonBoundary4QuqLuM1cE5lMwCy"; 

// set Content-Type in HTTP header 
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; 
[request setValue:contentType forHTTPHeaderField: @"Content-Type"]; 

// post body 
NSMutableData *body = [NSMutableData data]; 

for (int i=0; i<[imagesArray count]; i++) 
{ 
    UIImage *images=[imagesArray objectAtIndex:i]; 
    NSData* imageData = UIImageJPEGRepresentation(images, 0.7); 

    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image%d\"; filename=\"image%d\"\r\n", i+1,i+1] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[@"Content-Type:image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:imageData]; 
    [body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 

} 
//Close off the request with the boundary 
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 

// setting the body of the post to the request 
[request setHTTPBody:body]; 

// set URL 
[request setURL:[NSURL URLWithString:@"http://example.com"]]; // Give your URL here. 

[NSURLConnection sendAsynchronousRequest:request 
            queue:[NSOperationQueue mainQueue] 
         completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { 

          NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; 
          NSString *str = [NSString stringWithUTF8String:[data bytes]]; 
          NSLog(@"str %@",str); 
          if ([httpResponse statusCode] == 200) { 

           NSLog(@"success"); 
          }else{ 
           NSLog(@"failed"); 
          } 

         }]; 
} 

希望すると、これが役立ちます。

関連する問題