Botocore.exceptions.ClientError: An error occurred (InvalidArgument) when calling the PutObject operation: None upgrading to django-storages==1.14.4

I am encountering a ClientError: InvalidArgument when attempting to upload files to an S3 bucket using django-storages==1.14.4. This issue did not occur with django-storages==1.10, where the file upload process worked seamlessly. The error message is as follows:

Internal Server Error: /chats/generate-document/
Traceback (most recent call last):
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\django\views\generic\base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\django\utils\decorators.py", line 48, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\django\views\decorators\csrf.py", line 65, in _view_wrapper
    return view_func(request, *args, **kwargs)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\django\views\generic\base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\chat_app\views.py", line 235, in post
    user_chat.document.save(file_name, ContentFile(buffer.getvalue()))
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\django\db\models\fields\files.py", line 99, in save
    self.name = self.storage.save(name, content, max_length=self.field.max_length)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\django\core\files\storage\base.py", line 49, in save
    name = self._save(name, content)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\storages\backends\s3.py", line 564, in _save
    obj.upload_fileobj(content, ExtraArgs=params, Config=self.transfer_config)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\boto3\s3\inject.py", line 731, in object_upload_fileobj
    return self.meta.client.upload_fileobj(
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\boto3\s3\inject.py", line 642, in upload_fileobj
    return future.result()
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\s3transfer\futures.py", line 103, in result
    return self._coordinator.result()
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\s3transfer\futures.py", line 266, in result
    raise self._exception
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\s3transfer\tasks.py", line 139, in __call__
    return self._execute_main(kwargs)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\s3transfer\tasks.py", line 162, in _execute_main
    return_value = self._main(**kwargs)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\s3transfer\upload.py", line 764, in _main
    client.put_object(Bucket=bucket, Key=key, Body=body, **extra_args)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\botocore\client.py", line 569, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "C:\Users\tariq\OneDrive\Desktop\Important\aidocgen\venv\lib\site-packages\botocore\client.py", line 1023, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidArgument) when calling the PutObject operation: None

In django-storages==1.10, the file upload functionality worked correctly without any issues. The S3 bucket policies and IAM roles are properly configured to allow s3:PutObject, s3:GetObject, and s3:PutObjectAcl. The bucket is set with public read/write access.

I have verified the configuration and permissions, and the issue seems to be specific to the newer version of django-storages. Any guidance or insights on resolving this issue would be greatly appreciated, as it appears to be related to changes or updates introduced in django-storages==1.14.4.

Back to Top