title: S3ResponseError: 400 Bad Request
body: <p>I am working on a project on django 1.9 and using django-rest-framework. </p>
  
  <p><strong>Views.py:</strong></p>
  
  <pre><code>@parser_classes((FileUploadParser,))
  class upload_image(APIView):
      def post(self, request, format=None):
          file_obj = request.data['images']
          upload_s3 = FileUpload()
          folder_name = 'images'
          file_url = upload_s3.put(file_obj, folder_name, file_obj.name)
  class File_Upload:
      def __init__(self):
          self.env = {
              "aws_access_key_id": "*************",
              "aws_secret_access_key": "***********",
              "region_name": "Asia Pacific (Singapore)"
          }
          self.bucketname = "my_bucket"
  
          self.session = Session(**self.env)
  
          self.s3_client = self.session.client('s3')
  
      def put(self, bytes, folder, file_name):
          self.s3_client.put_object(Body=bytes, Bucket=self.bucketname, Key=folder + "/" + file_name)
          return "https://s3.%s.amazonaws.com/%s/%s/%s" % (self.env['region_name'], self.bucketname, folder, file_name)
  </code></pre>
  
  <p>On python shell I am able to upload as well as download images to and from amazon s3. I am using boto for this.</p>
  
  <p>Below is the code that I am using :</p>
  
  <pre><code>&gt;&gt;&gt; import boto
  &gt;&gt;&gt; import sys
  &gt;&gt;&gt; from boto.s3.connection import S3Connection
  &gt;&gt;&gt; from boto.s3.key import Key
  &gt;&gt;&gt; conn = boto.connect_s3("ACESS_KEY_ID","SECRET_ACCESS_KEY",host="s3-ap-southeast-1.amazonaws.com",is_secure = False)
  &gt;&gt;&gt; k = bucket.get_key("KEY_NAME")
  &gt;&gt;&gt; k.get_contents_to_filename("test.file")
  &gt;&gt;&gt; k.set_canned_acl('public-read')
  &gt;&gt;&gt; url = k.generate_url(0,query_auth=False,force_http=True)
  </code></pre>
  
  <p>I get a working url. But the problem comes when I want to do the same in the views.py(above code), I get this error:</p>
  
  <blockquote>
    <p>S3ResponseError: 400 Bad Request 
    Request Method:   POST Request
    URL:  <a href="http://127.0.0.1:8000/admin/imagedata/image/add/" rel="nofollow">http://127.0.0.1:8000/admin/imagedata/image/add/</a> 
    Django Version:    1.9 
    Exception Type:   S3ResponseError 
    Exception Value:  S3ResponseError: 400 
    Bad Request 
    Exception Location:/Library/Python/2.7/site-packages/boto/s3/bucket.py in_get_key_internal, line 235 
    Python Executable: /usr/bin/python Python Version: 2.7.10</p>
  </blockquote>
  
  <p>kindly tell me where the problem is? </p>