overhangio / openedx-scorm-xblock

SCORM XBlock for Open edX
GNU Affero General Public License v3.0
37 stars 48 forks source link

S3 storage not working #11

Closed lunika closed 3 years ago

lunika commented 3 years ago

Hi,

We are using the storage_func feature of this xblock to store file on S3 or swift. Unfortunately this is not working as expected. The Edxapp version used is Ironwood. The xblock version used is 9.2.4

Here the code of the storage function :

from storages.backends.s3boto import S3BotoStorage

def scorm_xblock_storage(xblock):
    return S3BotoStorage(
      bucket=XSCORM_AWS_STORAGE_BUCKET_NAME,
      access_key=XSCORM_AWS_S3_ACCESS_KEY_ID,
      secret_key=XSCORM_AWS_S3_SECRET_ACCESS_KEY,
      host=XSCORM_AWS_S3_HOST
    )

XBLOCK_SETTINGS["ScormXBlock"] = {
    "STORAGE_FUNC": scorm_xblock_storage,
}

When I upload a zip I always have the same error :

Traceback (most recent call last):
   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/exception.py", line 41, in inner
     response = get_response(request)
   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
     response = self._get_response(request)
   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 187, in _get_response
     response = self.process_exception_by_middleware(e, request)
   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 185, in _get_response
     response = wrapped_callback(request, *callback_args, **callback_kwargs)
   File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view
     return view_func(request, *args, **kwargs)
   File "/edx/app/edxapp/edx-platform/cms/djangoapps/contentstore/views/component.py", line 480, in component_handler
     resp = handler_descriptor.handle(handler, req, suffix)
   File "/usr/local/lib/python2.7/dist-packages/xblock/mixins.py", line 89, in handle
     return self.runtime.handle(self, handler_name, request, suffix)
   File "/edx/app/edxapp/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 1365, in handle
     return super(MetricsMixin, self).handle(block, handler_name, request, suffix=suffix)
   File "/usr/local/lib/python2.7/dist-packages/xblock/runtime.py", line 1037, in handle
     results = handler(request, suffix)
   File "/usr/local/lib/python2.7/dist-packages/openedxscorm/scormxblock.py", line 224, in studio_submit
     self.extract_package(package_file)
   File "/usr/local/lib/python2.7/dist-packages/openedxscorm/scormxblock.py", line 281, in extract_package
     dest_path, scorm_zipfile.open(zipinfo.filename),
   File "/usr/local/lib/python2.7/dist-packages/django/core/files/storage.py", line 54, in save
     return self._save(name, content)
   File "/usr/local/lib/python2.7/dist-packages/storages/backends/s3boto.py", line 417, in _save
     self._save_content(key, content, headers=headers)
   File "/usr/local/lib/python2.7/dist-packages/storages/backends/s3boto.py", line 428, in _save_content
     rewind=True, **kwargs)
   File "/usr/local/lib/python2.7/dist-packages/boto/s3/key.py", line 1207, in set_contents_from_file
     fp.seek(0, os.SEEK_SET)
 UnsupportedOperation: seek

The zip is uploaded and the error occurs when the zip content is saved.

lunika commented 3 years ago

In fact you have to backport this commit https://github.com/overhangio/openedx-scorm-xblock/commit/0109b45ee1cfb97350a61a7bb489530caa09da40 in version 9 and make a new release. With this modification it works.

Thanks

regisb commented 3 years ago

I'll backport the commit and release v9.2.5.