title: How does Alamofire "upload" images from Swift to a backend?
body: <p>I am trying to upload images from Swift to my Django backend so that I can store them in Google Cloud Storage and access them as "foreign keys" in my database models in django. There seems to be a built in library to bridge Django models and Google Storage <a href="https://django-storages.readthedocs.io/en/latest/backends/gcloud.html" rel="nofollow noreferrer">https://django-storages.readthedocs.io/en/latest/backends/gcloud.html</a>. </p>
  
  <p>Reference <a href="https://stackoverflow.com/questions/40519829/upload-image-to-server-using-alamofire">upload image to server using Alamofire</a>.
  Before sending an image to the backend, the image is converted into a UIImageJPEGRepresentation. How exactly is Alamofire then sending the image via "multipartFormData"? Is it simply sending the raw UIImageJPEGRepresentation as a string? </p>
  
  <p>I am asking this because I need to somehow convert this image data I receive in my backend and store it in a Django model and simultaneously upload it to Google Storage. </p>
  
  <p>From the documentation:</p>
  
  <pre><code>&gt;&gt;&gt; class Resume(models.Model):
  ...     pdf = models.FileField(upload_to='pdfs')
  ...     photos = models.ImageField(upload_to='photos')
  </code></pre>
  
  <p>To store a local file to cloud storage and at the same time in a model field:</p>
  
  <pre><code>&gt;&gt;&gt; obj1.pdf.save('django_test.txt', ContentFile('content'))
  &gt;&gt;&gt; obj1.pdf
  &lt;FieldFile: tests/django_test.txt&gt;
  </code></pre>
  
  <p>Would something like this work for an image sent from Alamofire?</p>
  
  <pre><code>&gt;&gt;&gt; obj1.photos.save(&lt;Insert whatever was sent from Alamofire&gt;)
  </code></pre>
  
  <p>If so, how do you access the data sent from Alamofire?</p>