title: Django S3 : UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
body: <p>I'm trying to use s3 to fetch images on my website.</p>
  <p>I'm trying to use get_object() to access to the image object.</p>
  <p>The part of the object that I want to return is the Body, which type is StreamingBody.
  I want to convert the StreamingBody into string to return it.</p>
  <p>Here is my code :</p>
  <pre><code>@api_view(['GET'])
  def get_image(request, image):
      &quot;&quot;&quot;Get image link&quot;&quot;&quot;
      key = &quot;media/&quot; + str(image)
      s3 = boto3.client('s3', config=Config(signature_version='s3v4', region_name=settings.AWS_S3_REGION_NAME))
      obj = s3.get_object(Bucket=settings.AWS_STORAGE_BUCKET_NAME, Key=key)
      
      return Response(obj['Body'].read().decode('utf-8'))
  </code></pre>
  <p><strong>urls.py</strong></p>
  <pre><code>from django.urls import path
  from store import views
  
  urlpatterns = [
      path('images/&lt;str:image&gt;', views.get_image),
  ]
  </code></pre>
  <p><code>obj['Body'].read()</code> return bytes that I'm tring to decode in utf-8.</p>
  <p>When I run <code>obj['Body'].read().decode('utf-8')</code>, I get this error : <strong>UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte</strong></p>
  <p>Thank you by advance for your help</p>
  <p><strong>UPDATE</strong></p>
  <p>I had to return the image data as an HttpResponse and without encoding :</p>
  <pre><code>image_data = obj['Body'].read()    
  return HttpResponse(image_data, content_type=&quot;image/jpeg&quot;)
  </code></pre>