Home > Back-end >  InvalidArgument when calling the PutObject operation: None
InvalidArgument when calling the PutObject operation: None

Time:04-14

i try to use boto3 and django-storages for media storage when i try to upload image its throws me an error like this:

ClientError at /admin/myschool/secondary/add/
An error occurred (InvalidArgument) when calling the PutObject operation: None

when i try to run python manage.py collectstatic :

  File "C:\Users\ADAMUDEE\AppData\Local\Programs\Python\Python310\lib\site-packages\botocore\client.py", line 745, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (InvalidArgument) when calling the PutObject operation: None

even in my admin panel.

i'm a begineer i don't know how this work this is my first time using AWS after i switch from cloudinary to aws S3.

i have setup everything as you can see here in my settings.py file:

AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY ''
AWS_STORAGE_BUCKET_NAME ''
AWS_S3_FILE_OVERWRITE = 'False'
AWS_DEFAULT_ACL = 'None'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

my public policy:

{
"Version": "2012-10-17",
"Statement": [
    {
        "Sid": "Statement1",
        "Principal": {},
        "Effect": "Allow",
        "Action": [],
        "Resource": []
    }
]

}

this is my Cross-origin resource sharing (CORS) i copied from stackoverflow, because i don't know how to create my own:

[
{
    "AllowedHeaders": [
        "*"
    ],
    "AllowedMethods": [
        "GET",
        "HEAD"
    ],
    "AllowedOrigins": [
        "*"
    ],
    "ExposeHeaders": [],
    "MaxAgeSeconds": 3000
}
]

Access control list (ACL):

Grantee
Objects
Bucket ACL
Bucket owner (your AWS account)
Canonical ID: ''

List
Write

Read
Write

Edit Object Ownership

ACLs disabled (recommended)

this my full error message:

ClientError at /posting/secondary

An error occurred (InvalidArgument) when calling the PutObject operation: None Request Method: POST Request URL: http://127.0.0.1:8000/posting/secondary Django Version: 4.0.1 Exception Type: ClientError Exception Value:
An error occurred (InvalidArgument) when calling the PutObject operation: None Exception Location: C:\Users\ADAMUDEE\AppData\Local\Programs\Python\Python310\lib\site-packages\botocore\client.py, line 745, in _make_api_call Python Executable: C:\Users\ADAMUDEE\AppData\Local\Programs\Python\Python310\python.exe Python Version: 3.10.0 Python Path:
['C:\Users\ADAMUDEE\Desktop\school\hello', 'C:\Users\ADAMUDEE\AppData\Local\Programs\Python\Python310\python310.zip', 'C:\Users\ADAMUDEE\AppData\Local\Programs\Python\Python310\DLLs', 'C:\Users\ADAMUDEE\AppData\Local\Programs\Python\Python310\lib', 'C:\Users\ADAMUDEE\AppData\Local\Programs\Python\Python310', 'C:\Users\ADAMUDEE\AppData\Roaming\Python\Python310\site-packages', 'C:\Users\ADAMUDEE\AppData\Local\Programs\Python\Python310\lib\site-packages'] Server time: Sun, 10 Apr 2022 23:27:11 0000

is anybody who can help me please ?

CodePudding user response:

ohh my God i solved my problem by genarating public access policy i also set my AWS_DEFAULT_ACL = 'public-read' and run collectstatic its shows me an error Could not connect to the endpoint URL: so i solve that in here when you finish come back to bucket you will see Only authorized users of this account once you see that then you can go ahead and run collectstatic again and then You are welcome.

  • Related