amazon web services - Django default_storage can`t find an existing file - Stack Overflow

I'm setting up work with my django app, but I ran into a problem when checking for any file in S3

I'm setting up work with my django app, but I ran into a problem when checking for any file in S3 storage.

I can't figure out why I can't use the exists() method in my code. I searched for an error for a long time, but it turned out that the exists() method always returns False to me.

Here is an example:

>>> from django.core.files.storage import default_storage
>>> print(default_storage.listdir(""))

(['media', 'preview'], ['address_preview_1.png','address_preview_35.jpg'])
>>> 
>>> print(default_storage.listdir("media"))
([], ['address_preview_35.jpg'])
>>> print(default_storage.exists('address_preview_35.jpg'))
False
>>> print(default_storage.exists('/media/address_preview_35.jpg'))
False
>>> print(default_storage.exists('media/address_preview_35.jpg'))
False
>>> print(default_storage.location)
media

We see that the file "address_preview_35.jpg " there is both in the root of the repository and in the "media" folder.

All arguments in settings.py are configured as described in the documentation. The image files are definitely on the server. We can open it. We can get the image from the full link. We can upload new files to the server and we can delete old ones. We can do everything EXCEPT check whether there is a file on the server or not. What am I doing wrong!?

I tried accessing the server directly and via s3cmd. I tried accessing the repository in the module via

from storages.backends.s3boto3 import S3Boto3Storage

s3_storage = S3Boto3Storage()
print(s3_storage.exists("media/address_preview_35.jpg"))

the result is the same - I see the file in the list, but when checking exists(), I get False.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744743598a4591175.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信