2016-10-13 9 views
1

失敗しましたが、私は構築し、それが、これは私のSWIFTコード」Alamofireマルチパートの画像アップロードは、私がAlamofireで画像をアップロードするマルチパートを使用

Alamofire.upload(
    multipartFormData: { multipartFormData in 
     multipartFormData.append(d1, withName: "file",fileName: "file.jpg", mimeType: "image/jpg")// d1 in let d1 = UIImageJPEGRepresentation(uiimage, 1) 
    }, 
    to: "mysite/upload.php", 
    encodingCompletion: { encodingResult in 
     switch encodingResult { 
     case .success(let upload, _, _): 
      upload.responseJSON { response in 
       debugPrint(response) 
      } 
     case .failure(let encodingError): 
      print(encodingError) 
     } 
    } 
) 

と私のPHPコード

$ip = $_SERVER['REMOTE_ADDR']; 
$timestp = DATE("Y-m-d H:i:s"); 
$milliseconds = round(microtime(true) * 1000); 
$image_name=date("dmyHis").$milliseconds.$psmemid.$psplace.$pscate.".jpg"; 
$imgpath = "../Image/"; 
$newname = $imgpath.$image_name; 
$copied = copy($_FILES['club_image']['tmp_name'], $newname); 
    $upload = $imgpath . basename($_FILES['club_image']['tmp_name']); 
    ini_set('display_errors', 1); 
    ini_set('display_startup_errors', 1); 
    error_reporting(E_ALL); 

とログです を失敗したアップロードアップロード後は

[Response]: <NSHTTPURLResponse: 0x600000428f40> { URL: mysite/upload.php } { status code: 200, headers { 
    Connection = "keep-alive"; 
    "Content-Length" = 0; 
    "Content-Type" = "text/html"; 
    Date = "Thu, 13 Oct 2016 04:33:03 GMT"; 
    Server = nginx; 
    Vary = "User-Agent"; 
    "X-Powered-By" = "PHP/5.3.29"; 
} } 
[Data]: 0 bytes 
[Result]: SUCCESS: 
[Timeline]: Timeline: { "Request Start Time": 498025982.810, "Initial Response Time": 498025982.843, "Request Completed Time": 498025983.432, "Serialization Completed Time": 498025983.432, "Latency": 0.033 secs, "Request Duration": 0.622 secs, "Serialization Duration": 0.000 secs, "Total Duration": 0.622 secs } 

ありがとうございます。

+0

多分あなたは、私はそれは成功だアップロードするために使用するために、古いスタックの質問で見たので、私は感謝 –

+0

を追加する必要があります(私は 'Alamofire.upload(fileURLを使用する:「HTTPS ://httpbin.org/post ").responseJSON { の応答debugPrint(応答) }'それは失敗しました) –

+0

@iDeveloper私はマルチパートを使用してこれを追加しましたエラーログ –

答えて

2

要求が間違ったファイル名を送信しています。

Alamofire.upload(multipartFormData: { multipartFormData in 
      multipartFormData.append(d1, withName: "club_image",fileName: "file.jpg", mimeType: "image/jpg")// d1 in let d1 = UIImageJPEGRepresentation(uiimage, 1) 
     }, 
    to:"mysite/upload.php") 
    { (result) in 
     switch result { 
     case .success(let upload, _, _): 

      upload.uploadProgress(closure: { (progress) in 
       print("Upload Progress: \(progress.fractionCompleted)") 
      }) 

      upload.responseJSON { response in 
       print(response.result.value) 
      } 

     case .failure(let encodingError): 
      print(encodingError) 
     } 
    } 
+0

それは動作します、ありがとう –

+0

その私の喜び。親切にUpvoteそれが有用な場合。 –

関連する問題