Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot check file size #18

Closed
ghost opened this issue May 21, 2021 · 3 comments · Fixed by #19
Closed

Cannot check file size #18

ghost opened this issue May 21, 2021 · 3 comments · Fixed by #19

Comments

@ghost
Copy link

ghost commented May 21, 2021

I have encountered an error in BackblazeB2Storage detailed below.
This happens at least in b2sdk 1.7.0 and 1.8.0 (didn't check earlier versions at the moment)
I guess there was a breaking change in b2sdk.

from djano.db import models
from django_backblaze_b2 import BackblazeB2Storage

class SomeModel(models.Model):
     file = models.FileField(
        storage=BackblazeB2Storage, blank=True
    )
    
obj = SomeModel(file="key/of/existing/file.pdf")

# This raises the exception below
# If a non-existent file path was given, it returns 0 instead.
obj.file.size

# This works
x.file.storage._fileInfo(x.file.name).size

-------------------------------------------------------
  File "/usr/local/lib/python3.8/site-packages/django/db/models/fields/files.py", line 70, in size
    return self.storage.size(self.name)
  File "/usr/local/lib/python3.8/site-packages/django_backblaze_b2/storage.py", line 210, in size
    return fileInfo.get("size", 0) if fileInfo else 0
AttributeError: 'FileVersionInfo' object has no attribute 'get'
@ehossack
Copy link
Owner

Yeah, it looks like they're (finally) accelerating their release cycle. I'll update the library this weekend.

@ehossack
Copy link
Owner

ehossack commented Jun 1, 2021

For reference, waiting on a 1.9.0 release. I submitted a bugfix to the b2sdk. Looks like the bug you encountered was actually in my implementation, but might as well release a more up-to-date implementation.

@ehossack
Copy link
Owner

ehossack commented Jun 8, 2021

Fixed in library version 2.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant