Cannot upload profile image in Nutmeg

Hi there,
Testing Nutmeg, I get this error when trying to upload a profile image.

2022-06-13 15:56:12,893 ERROR 7 [django.request] [user 5] [ip 10.x.x.x] log.py:224 - Internal Server Error: /api/user/v1/accounts/andres/image
Traceback (most recent call last):
  File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/pyenv/versions/3.8.12/lib/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/openedx/venv/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/views.py", line 497, in dispatch
    self.initial(request, *args, **kwargs)
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/views.py", line 414, in initial
    self.perform_authentication(request)
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/views.py", line 324, in perform_authentication
    request.user
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/request.py", line 227, in user
    self._authenticate()
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/request.py", line 380, in _authenticate
    user_auth_tuple = authenticator.authenticate(self)
  File "/openedx/venv/lib/python3.8/site-packages/edx_rest_framework_extensions/auth/jwt/authentication.py", line 75, in authenticate
    self.enforce_csrf(request)
  File "/openedx/venv/lib/python3.8/site-packages/edx_rest_framework_extensions/auth/jwt/authentication.py", line 167, in enforce_csrf
    reason = check.process_view(request, None, (), {})
  File "/openedx/venv/lib/python3.8/site-packages/django/middleware/csrf.py", line 297, in process_view
    request_csrf_token = request.POST.get('csrfmiddlewaretoken', '')
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/request.py", line 431, in POST
    self._load_data_and_files()
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/request.py", line 279, in _load_data_and_files
    self._data, self._files = self._parse()
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/request.py", line 329, in _parse
    stream = self.stream
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/request.py", line 203, in stream
    self._load_stream()
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/request.py", line 309, in _load_stream
    self._stream = io.BytesIO(self.body)
  File "/openedx/venv/lib/python3.8/site-packages/rest_framework/request.py", line 416, in __getattr__
    return getattr(self._request, attr)
  File "/openedx/venv/lib/python3.8/site-packages/django/http/request.py", line 328, in body
    raise RawPostDataException("You cannot access body after reading from request's data stream")
django.http.request.RawPostDataException: You cannot access body after reading from request's data stream
[pid: 7|app: 0|req: 18/64] 10.x.x.x () {52 vars in 3429 bytes} [Mon Jun 13 15:55:58 2022] POST /api/user/v1/accounts/andres/image => generated 9380 bytes in 15141 msecs (HTTP/1.1 500) 9 headers in 641 bytes (264 switches on core 0)

Thank you very much, Andres.

Admittedly I cannot find a test case in our test sheet for this. Therefore I will add this test case for Olive.

However, it’s working for me: Learner Profile | Open edX Demo Site

Hi Dean!
I think I’ve found something. I tried in the demo site with the same image (12MB jpg), and it failed! But then I tried with a smaller one (1MB), and it worked. Looks like it’s got to do with the size. It’s reasonable to have a limit. Maybe we can add a file size check before uploading?

Hi Andres, smart thinking. It must be file size related then.

Yes some kind of check before uploading, or maybe a useful error message? Whichever option is easier to develop/implement.