Question

I'm working with amazon S3 storage and have unexpected behavior: storage.exists() returns False for directories. Am I doing everything right? As I understand django documentation, it should return True https://docs.djangoproject.com/en/dev/ref/files/storage/

from storages.backends.s3boto import S3BotoStorage

s = S3BotoStorage(bucket='bucketname')
s.listdir('.')
    ([u'test_elf'], [u'327.jpg',u'avatar2.jpg'])
s.exists(u'avatar2.jpg')
    True
s.exists(u'test_elf')
    False  <-- ??
Was it helpful?

Solution

s3 only emulates folders. If you have such structure of files on s3

avatar1.jpg
avatar2.jpg
folder --
          avatar3.jpg
          avatar4.jpg
one_more.png
last_image.jpg

than you have 6 logical instances on your bucket:

avatar1.jpg
avatar2.jpg
folder/avatar3.jpg
folder/avatar4.jpg
one_more.png
last_image.jpg

I think you are free to create a file "folder" in the root wich will be incompartable with a usual filesystem structure but possible on s3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top