escaped / django-video-encoding

django-video-encoding helps to convert your videos into different formats and resolutions.
BSD 3-Clause "New" or "Revised" License
116 stars 45 forks source link

fix #13 #14

Closed bashu closed 4 years ago

escaped commented 5 years ago

Many thanks for your contribution @bashu! Makes sense to me to officially support different storages. Unfortunately, I do not have much experience with working with S3 and hope you can help me here. I commented you PR with some concerns, which you might be able to address. Additionally, I would love if you could fix the failing tests and add a test, which verifies your implementation (eg. using moto). Thanks. Your contribution is very much appreciated :)

lifenautjoe commented 5 years ago

Hi all, looking into using the library but indeed we're using a custom storage for S3.

Is there a way to use it at the moment?

Cheers and thanks for the great work!

lifenautjoe commented 5 years ago

Upon inspection, I've noticed the VideoField inherits from the FileField model which contains a storage parameter. This PR is then not needed?

escaped commented 5 years ago

@lifenautjoe thanks for looking into this. Unfortunately, I currently don't have much time to investigate the use of different storages. It could be that this PR is not needed, but it seems like it didn't work for @bashu in the first place and he tried to fix it. It would be great if you could give him a hand and help us providing support for different storages or help us to clarify how to use a different storage backend (preferably with a test, which verifies that)! Many thanks!

lifenautjoe commented 5 years ago

I'll do some testing and be right back to you.

bashu commented 5 years ago

Upon inspection, I've noticed the VideoField inherits from the FileField model which contains a storage parameter.

@lifenautjoe then make it work!

lifenautjoe commented 5 years ago

Update: doesn't work 🙃.

@bashu I didn't mean it in a bad way, I was wondering if by having a FileField, the support would be the same. However it's not the case.

The error is

This backend doesn't support absolute paths.

The full stack trace is

NotImplementedError: This backend doesn't support absolute paths.
  File "django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "rest_framework/views.py", line 505, in dispatch
    response = self.handle_exception(exc)
  File "rest_framework/views.py", line 465, in handle_exception
    self.raise_uncaught_exception(exc)
  File "rest_framework/views.py", line 476, in raise_uncaught_exception
    raise exc
  File "rest_framework/views.py", line 502, in dispatch
    response = handler(request, *args, **kwargs)
  File "openbook_posts/views/post_media/views.py", line 32, in put
    user.add_media_to_post_with_uuid(post_uuid=post_uuid, file=file, order=order)
  File "openbook_auth/models.py", line 1785, in add_media_to_post_with_uuid
    return self.add_media_to_post(post=post, file=file, order=order)
  File "openbook_auth/models.py", line 1789, in add_media_to_post
    post.add_media(file=file, order=order)
  File "openbook_posts/models.py", line 352, in add_media
    post_video = self._add_media_video(video=file, order=order)
  File "openbook_posts/models.py", line 374, in _add_media_video
    return PostVideo.create_post_media_video(file=video, post_id=self.pk, order=order)
  File "openbook_posts/models.py", line 625, in create_post_media_video
    post_video = cls.objects.create(file=file, post_id=post_id, hash=hash, thumbnail=File(thumbnail_file), )
  File "django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "django/db/models/query.py", line 422, in create
    obj.save(force_insert=True, using=self.db)
  File "django/db/models/base.py", line 741, in save
    force_update=force_update, update_fields=update_fields)
  File "django/db/models/base.py", line 779, in save_base
    force_update, using, update_fields,
  File "django/db/models/base.py", line 870, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "django/db/models/base.py", line 908, in _do_insert
    using=using, raw=raw)
  File "django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "django/db/models/query.py", line 1186, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "django/db/models/sql/compiler.py", line 1334, in execute_sql
    for sql, params in self.as_sql():
  File "django/db/models/sql/compiler.py", line 1278, in as_sql
    for obj in self.query.objs
  File "django/db/models/sql/compiler.py", line 1278, in <listcomp>
    for obj in self.query.objs
  File "django/db/models/sql/compiler.py", line 1277, in <listcomp>
    [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
  File "django/db/models/sql/compiler.py", line 1228, in pre_save_val
    return field.pre_save(obj, add=True)
  File "django/db/models/fields/files.py", line 288, in pre_save
    file.save(file.name, file.file, save=False)
  File "django/db/models/fields/files.py", line 88, in save
    setattr(self.instance, self.field.name, self.name)
  File "django/db/models/fields/files.py", line 346, in __set__
    self.field.update_dimension_fields(instance, force=True)
  File "video_encoding/fields.py", line 53, in update_dimension_fields
    *args, **kwargs)
  File "django/db/models/fields/files.py", line 449, in update_dimension_fields
    width = file.width
  File "video_encoding/files.py", line 18, in _get_width
    return self._get_video_info().get('width', 0)
  File "video_encoding/files.py", line 42, in _get_video_info
    path = os.path.abspath(self.path)
  File "django/db/models/fields/files.py", line 57, in path
    return self.storage.path(self.name)
  File "django/core/files/storage.py", line 109, in path
    raise NotImplementedError("This backend doesn't support absolute paths.")

The issue is specifically that a django storage cannot rely on absolute paths.

image

escaped commented 4 years ago

Thank you so much for looking into this @bashu! I added you as a contributor but will close this PR in favour of #19

bashu commented 4 years ago

@escaped looking for new release ! 👍