klis87 / django-cloudinary-storage

Django package that provides Cloudinary storages for both media and static files as well as management commands for removing unnecessary files.
MIT License
131 stars 26 forks source link

Static files don't work #33

Closed mabdullahabid closed 2 years ago

mabdullahabid commented 3 years ago

Hi there, running collectstatic raises the following errors.

hashed

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
    collected = self.collect()
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 128, in collect
    for original_path, processed_path, processed in processor:
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/cloudinary_storage/storage.py", line 313, in post_process
    for response in super(HashCloudinaryMixin, self).post_process(paths, dry_run, **options):
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 399, in post_process
    yield from super().post_process(*args, **kwargs)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 231, in post_process
    for name, hashed_name, processed, _ in self._post_process(paths, adjustable_paths, hashed_files):
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 288, in _post_process
    content = pattern.sub(converter, content)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 187, in converter
    hashed_url = self._url(
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 126, in _url
    hashed_name = hashed_name_func(*args)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/storage.py", line 338, in _stored_name
    cache_name = self.clean_name(self.hashed_name(name))
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/cloudinary_storage/storage.py", line 284, in hashed_name
    content = open(absolute_path, 'rb')
TypeError: expected str, bytes or os.PathLike object, not NoneType

unhashed

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
    collected = self.collect()
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
    handler(path, prefixed_path, storage)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/cloudinary_storage/management/commands/collectstatic.py", line 30, in copy_file
    super(Command, self).copy_file(path, prefixed_path, source_storage)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 348, in copy_file
    self.storage.save(prefixed_path, source_file)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/django/core/files/storage.py", line 54, in save
    return self._save(name, content)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/cloudinary_storage/storage.py", line 236, in _save
    super(StaticCloudinaryStorage, self)._save(name, content)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/cloudinary_storage/storage.py", line 68, in _save
    response = self._upload(name, content)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/cloudinary_storage/storage.py", line 195, in _upload
    return cloudinary.uploader.upload(content, public_id=name, resource_type=resource_type,
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/cloudinary/uploader.py", line 46, in upload
    return call_cacheable_api("upload", params, file=file, **options)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/cloudinary/uploader.py", line 394, in call_cacheable_api
    result = call_api(action, params, http_headers, return_error, unsigned, file, timeout, **options)
  File "/home/ubuntu/repos/therepublic-app/venv/lib/python3.8/site-packages/cloudinary/uploader.py", line 477, in call_api
    raise Error(result["error"]["message"])
cloudinary.exceptions.Error: Empty file
klis87 commented 2 years ago

Doesn't it work for you for any file? Did you do everything as described in https://github.com/klis87/django-cloudinary-storage#usage-with-static-files? Asking as I know some people use static files without any issues, so it is either a file issue or a configuration issue probably.

mabdullahabid commented 2 years ago

@klis87 I did try that but it didn't work so I had to use this https://github.com/tiagocordeiro/dj3-cloudinary-storage with some minor updates

aayobam commented 11 months ago

how were you able to resolves the issue with dj3, i'm also experience the error here with django-cloudinary-storage @mabdullahabid

klis87 commented 11 months ago

Do you know what causes this issue? Outdated cloudinary package perhaps?