title: Upload file to AWS with Swift trough php
body: <p>i found this swift code and seems to work fine but i don't know how to parse it in php.
  I need to send image data and parameters (eg. name = Steve &amp; age = 20) to a php web service that can upload image on AWS S3 storage and do something on my mysql db.</p>
  <p>my swift code is:</p>
  <pre><code>&lt;pre&gt;
  
         
  
  func upload(fileData:Data, fileName:String , completion: @escaping (_ fileURL:String?, _ error:String?) -&gt; Void) {
          let boundary = &quot;----------V2y2HFg03eptjbaKO0j1&quot;
          let requestUrl = NSURL(string: self.WSurl.dammiUrl(m_path: .uploadCertificatoMedico, query: &quot;&quot;))
          var request = URLRequest(url: requestUrl! as URL)
          request.httpMethod = &quot;POST&quot;
          request.setValue(&quot;multipart/form-data; boundary=\(boundary)&quot;, forHTTPHeaderField: &quot;Content-Type&quot;)
   let fname = &quot;certificatoMedico.jpg&quot;
          let mimetype = &quot;image/png&quot;
  
          var body = Data()
          body.append(&quot;--\(boundary)\r\n&quot;.data(using: .utf8)!)
          body.append(&quot;Content-Disposition:form-data; name=\&quot;nomeDb\&quot;\r\n\r\n&quot;.data(using: .utf8)!)
          body.append(&quot;\(nomeDb)\r\n&quot;.data(using: .utf8)!)
  
          body.append(&quot;--\(boundary)\r\n&quot;.data(using: .utf8)!)
          body.append(&quot;Content-Disposition:form-data; name=\&quot;codFiscale\&quot;\r\n\r\n&quot;.data(using: .utf8)!)
          body.append(&quot;SCRSFN77C19F205K\r\n&quot;.data(using: .utf8)!)
  
          body.append(&quot;--\(boundary)\r\n&quot;.data(using: .utf8)!)
          body.append(&quot;Content-Disposition:form-data; name=\&quot;file\&quot;; filename=\&quot;\(fname)\&quot;\r\n&quot;.data(using: .utf8)!)
          body.append(&quot;Content-Type: \(mimetype)\r\n\r\n&quot;.data(using: .utf8)!)
          body.append(fileData)
          body.append(&quot;\r\n&quot;.data(using: .utf8)!)
  
          body.append(&quot;--\(boundary)--\r\n&quot;.data(using: .utf8)!)
  
          request.httpBody = body
  
          let session = URLSession.shared
          let task = session.dataTask(with: request as URLRequest) { (data, response, error) in
              guard let _:Data = data as Data?, let _:URLResponse = response, error == nil else {
                  DispatchQueue.main.async {
                      completion(nil, error!.localizedDescription)
                  }
                  return
              }
              if let response = String(data: data!, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue)) {
                  print(&quot;- - - - SS96 -&gt; RESPONSE: &quot; + response)
                  DispatchQueue.main.async {
                      completion(response, nil)
                  }
                  // NO response
              } else {
                  DispatchQueue.main.async {
                      completion(nil, nil)
                  }
              }
          }
          task.resume()
      }
  
  
  
  &lt;/pre&gt;
  </code></pre>
  <p>here how i call this:</p>
  <pre><code>&lt;pre&gt;
  guard let image = self.imageView.image else {
  print(&quot;imageView.image == nil&quot;)
              return
          }
  
          guard let image_data = image.pngData() else {
              print(&quot;UIImagePNGRepresentation returned nil&quot;)
              return
          }
  
          self.upload(fileData: image_data, fileName: &quot;test.jpg&quot;) { fileURL, error in
              if error == nil {
                  print(&quot;url = \(fileURL)&quot;)
              }
          }
  &lt;/pre&gt;
  </code></pre>
  <p>can you tell me the best way to get variables and image data to upload on AWS S3 on php?</p>