title: iOS - Failed to upload video file from swift to FastAPI server
body: <p>I took the code for uploading the video file from <a href="https://stackoverflow.com/questions/49649315/">this question</a>, however, an error occurs.</p>
  <p>This is the code to select a video from an album:</p>
  <pre class="lang-swift prettyprint-override"><code>var videoURL: URL?
  
  extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
      func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
  
          picker.dismiss(animated: true, completion: nil)
          if let pickedVideo = info[UIImagePickerController.InfoKey.mediaURL] as? URL {
              videoURL = pickedVideo
  }
  </code></pre>
  <p>This is the code to upload the video to the server.</p>
  <pre class="lang-swift prettyprint-override"><code>func uploadImage(imageURL: URL?) {
          
          let URL = &quot;http://127.0.0.1:8000/uploadfiles&quot;
          let header : HTTPHeaders = [
              &quot;Content-Type&quot; : &quot;application/json&quot;]
      
      let timestamp = NSDate().timeIntervalSince1970
      
      AF.upload(multipartFormData: { multipartFormData in
          multipartFormData.append(imageURL!, withName: &quot;video&quot;, fileName: &quot;\(timestamp).mp4&quot;, mimeType: &quot;\(timestamp).mp4&quot;)
          
      }, to: URL, usingThreshold: UInt64.init(), method: .post, headers: header).response { response in
          guard let statusCode = response.response?.statusCode,
                statusCode == 200
          else { return }
  </code></pre>
  <pre><code>@IBAction func ButtonClicked(_ sender: UIButton) {
          do {
              uploadImage(imageURL: videoURL!)
   
          } catch {
          }
      }
  
  </code></pre>
  <p>This is the FastAPI server code:</p>
  <pre class="lang-py prettyprint-override"><code>from fastapi import FastAPI, File, UploadFile
  from typing import List
  import os
  
  app = FastAPI()
  
  @app.get(&quot;/&quot;)
  def read_root():
    return { &quot;Hello&quot;: &quot;World&quot; }
  
  @app.post(&quot;/files/&quot;)
  async def create_files(files: List[bytes] = File(...)):
      return {&quot;file_sizes&quot;: [len(file) for file in files]}
  
  @app.post(&quot;/uploadfiles&quot;)
  async def create_upload_files(files: List[UploadFile] = File(...)):
      print('here')
      UPLOAD_DIRECTORY = &quot;./&quot;
      for file in files:
          contents = await file.read()
          with open(os.path.join(UPLOAD_DIRECTORY, file.filename), &quot;wb&quot;) as fp:
              fp.write(contents)
          print(file.filename)
      return {&quot;filenames&quot;: [file.filename for file in files]}
  </code></pre>
  <p>This is the error:</p>
  <pre><code>INFO:     127.0.0.1:65191 - &quot;POST /uploadfiles HTTP/1.1&quot; 422 Unprocessable Entity
  </code></pre>