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

S3: Failed to save image on recipe import #2259

Closed
AdrienPoupa opened this issue Jan 9, 2023 · 3 comments
Closed

S3: Failed to save image on recipe import #2259

AdrienPoupa opened this issue Jan 9, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@AdrienPoupa
Copy link

AdrienPoupa commented Jan 9, 2023

Tandoor Version

1.4.5

Setup

Docker / Docker-Compose

Reverse Proxy

Others (please state below)

Other

CloudFlare Tunnel (not relevant I think)

Bug description

When I try to import a recipe, the image fails to be uploaded to my S3 bucket.

It is not a configuration issue, since if I edit the recipe and upload the image manually, it works and the image is uploaded to the S3 bucket. This happened with all recipes I tried to import (5+)

This StackOverflow post seems to be relevant: https://stackoverflow.com/questions/72285087/django-uploaded-file-validation-leads-to-inmemoryuploadedfile-is-not-supported

Relevant logs

Failure on recipe import:

ERROR:django.request:Internal Server Error: /api/recipe/17/image/
Traceback (most recent call last):
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
tandoor-nginx_recipes-1   | 172.20.0.2 - - [09/Jan/2023:05:45:10 +0000] "PUT /api/recipe/17/image/ HTTP/1.1" 500 145 "xxx/data/import/url" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0" "2607:fa49:3f41:9100:a860:d740:61e:253b"
    response = get_response(request)
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/opt/recipes/venv/lib/python3.10/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/recipes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/opt/recipes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/opt/recipes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/opt/recipes/venv/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/opt/recipes/cookbook/views/api.py", line 856, in image
    obj.save()
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/base.py", line 806, in save
    self.save_base(
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/base.py", line 857, in save_base
    updated = self._save_table(
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/base.py", line 961, in _save_table
    values = [
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/base.py", line 965, in <listcomp>
    (getattr(self, f.attname) if raw else f.pre_save(self, False)),
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/fields/files.py", line 316, in pre_save
    file.save(file.name, file.file, save=False)
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/db/models/fields/files.py", line 92, in save
    self.name = self.storage.save(name, content, max_length=self.field.max_length)
  File "/opt/recipes/venv/lib/python3.10/site-packages/django/core/files/storage.py", line 57, in save
    name = self._save(name, content)
  File "/opt/recipes/venv/lib/python3.10/site-packages/storages/backends/s3boto3.py", line 457, in _save
    obj.upload_fileobj(content, ExtraArgs=params, Config=self._transfer_config)
  File "/opt/recipes/venv/lib/python3.10/site-packages/boto3/s3/inject.py", line 725, in object_upload_fileobj
    return self.meta.client.upload_fileobj(
  File "/opt/recipes/venv/lib/python3.10/site-packages/boto3/s3/inject.py", line 636, in upload_fileobj
    return future.result()
  File "/opt/recipes/venv/lib/python3.10/site-packages/s3transfer/futures.py", line 103, in result
    return self._coordinator.result()
  File "/opt/recipes/venv/lib/python3.10/site-packages/s3transfer/futures.py", line 266, in result
    raise self._exception
  File "/opt/recipes/venv/lib/python3.10/site-packages/s3transfer/tasks.py", line 269, in _main
    self._submit(transfer_future=transfer_future, **kwargs)
  File "/opt/recipes/venv/lib/python3.10/site-packages/s3transfer/upload.py", line 579, in _submit
    upload_input_manager = self._get_upload_input_manager_cls(
  File "/opt/recipes/venv/lib/python3.10/site-packages/s3transfer/upload.py", line 546, in _get_upload_input_manager_cls
    raise RuntimeError(
RuntimeError: Input c9ede5be-215a-42e9-84b4-fced39fee8a5_17.jpg of type: <class 'django.core.files.base.File'> is not supported.
172.20.0.6 - - [09/Jan/2023:00:45:10 -0500] "PUT /api/recipe/17/image/ HTTP/1.0" 500 145 "xxx/data/import/url" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0"
@vabene1111
Copy link
Collaborator

thanks for reporting, can confirm this on the hosted instance which uses S3 as well.

Will look into why this is not working.

@vabene1111 vabene1111 added the bug Something isn't working label Jan 10, 2023
@vabene1111
Copy link
Collaborator

ok i am not sure why this used to work before but maybe something old got deprecated or so because i was not correctly storing the file in the media handling function. This appears to have worked in the past but does no longer.

I have changed the code to now work correctly

@AdrienPoupa
Copy link
Author

Thank you! Much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants