2017-07-02 32 views
0

我試圖找回它的服務器端解決關於與AlamofireLink)文件上傳(雨燕3.0)和檢索它們使用Slim PHPLink)微架構的服務器端的問題。上傳文件,即使Alamofire並搭配修身PHP

我試圖上傳使用

Alamofire.upload(multipartFormData:{ 
multipartFormData in 
    multipartFormData.append("value".data(/* ... */)!, withName :"key") 

    var idx = 1; 
    for imageRepresentation in imageData { 
     let pictureName = "pictures[]" 
     multipartFormData.append(imageRepresentation, withName: pictureName, mimeType: "image/jpeg") 
     idx += 1 
    } 

}, 
to: uploadUrl, 
method:.post, 
headers: httpHeaders, 
encodingCompletion: /* ... */ 

在這裏,我幾乎可以肯定,這個腳本是工作的罰款從iPhone拍攝照片,因爲當我打https://httpbin.org/post我回來了編碼data base 64像我已經上傳,所以我很確定這個問題來自我的服務器端代碼。

所以,正如我所說,我使用修身PHPLink)服務器端使用這條路線

$this->post('/upload', function ($request, $response, $args) { 

     $request->getParsedBody(); //null 
     $request->getQueryParams(); // [] 
     $request->getBody(); // {} 
     $request->getUploadedFiles(); // [] 

     return /*Some JSON */ 

    })->setName('upload'); 

我錯過了什麼?有什麼我不明白的嗎? 我已經嘗試過

而且最奇怪的是,從爪子API瀏覽器

任何幫助將是非常讚賞執行腳本時就像一個魅力!謝謝。

回答

0

用於上傳從照片庫中選擇圖像

在斯威夫特3和Alamofire 4

下面是如何使用Alamofire

  1. 上傳全面實施以下內容添加到您的ViewController類別:

    UIImagePickerControllerDelegateUINavigationControllerDelegate

  2. 創建按鈕:

首先創建一個按鈕並執行以下的方法在它爲選擇器視圖

@IBAction func btnSelectProfileImageClicked(_ sender: Any) { 

    let ImagePicker = UIImagePickerController() 
    ImagePicker.delegate = self 
    ImagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary 

    self.present(ImagePicker, animated: true, completion: nil) 


} 
  • 然後實現以下UIPicker方法:

    func imagePickerController(_ picker: UIImagePickerController,didFinishPickingMediaWithInfo info:[String : Any]) 
    {Imgprofile.image = info[UIImagePickerControllerOriginalImage] as? UIImage 
    self.dismiss(animated: true, completion: nil)} 
    
  • 使另一個按鈕通過d ATA到URL使用Alamofire並給出一個@IBAction出口給它吧:

  • 輸入下面的數據吧

    @IBAction func btnUpdateProfileSelected(_ sender: Any) { 
    
        Alamofire.upload(multipartFormData: { (multipartFormData) in 
         multipartFormData.append(UIImageJPEGRepresentation(self.Imgprofile.image!, 1)!, withName: "Prescription", fileName: "Profile_Image.jpeg", mimeType: "image/jpeg") 
        }, to:" Your URL Here where You want to Upload") 
        { (result) in 
         switch result { 
         case .success(let upload, _, _): 
          print(result) 
    
          upload.uploadProgress(closure: { (progress) in 
           print(progress) 
          }) 
    
          upload.responseJSON { response in 
           //print response.result 
           print(response); 
          } 
    
         case .failure(let encodingError): 
          print(encodingError); 
         } 
        } 
    } 
    

    這就是所有

    希望這有助於

    對於全部示例代碼或任何懷疑請評論。我會爲您提供 的示例代碼。其中包括抓取以及使用Alamofire上傳數據的 。

    感謝

    +0

    我已經知道了。 該問題位於Alamofire有關文件上傳的「Content-type」上。 –