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

Unsupported Media Type with Chunked Uploads #123

Open
bptarpley opened this issue Sep 20, 2024 · 2 comments
Open

Unsupported Media Type with Chunked Uploads #123

bptarpley opened this issue Sep 20, 2024 · 2 comments

Comments

@bptarpley
Copy link

Greetings! I'm excited about using this package to handle my integration with Filepond. Unfortunately, when setting up my client according to your documentation, my Django app returns this response:

method: PATCH
code: 415
message: Unsupported media type "application offset/octet stream"

You documentation mentions no further configuration necessary for supporting chunked uploads, but I can't seem to get it to work. I'm using:

django 4.2.7
djangorestframework 3.14.0
django-drf-filepond 0.5.0

In settings.py, I tried specifying "rest_framework.parsers.FileUploadParser" under 'DEFAULT_PARSER_CLASSES' for the REST_FRAMEWORK setting but no luck.

What am I missing? Many thanks in advance!

@bptarpley
Copy link
Author

bptarpley commented Sep 21, 2024

Okay, so after a lot of sleuthing, it looks like FilePond is setting the CONTENT_TYPE header to "application%2Foffset%2Boctet-stream" which looks like a URL encoded version of the expected "application/offset+octet-stream". Here's my Filepond (v4.31.3) config on the frontend:

  FilePond.create(target[0], {
          chunkUploads: true,
          chunkSize: 500000,
          server: {
              url: '/fp',
              process: '/process/',
              patch: '/patch/',
              revert: '/revert/',
              fetch: '/fetch/?target=',
              headers: {'X-CSRFToken': crsf_token}
          }
      })

A hacky bit of Django middleware placed near the top of the stack fixes the problem:

  class ChunkedTransferMiddleware:
  
      def __init__(self, get_response):
          self.get_response = get_response
  
      def __call__(self, request):
          if 'CONTENT_TYPE' in request.headers and request.headers['CONTENT_TYPE'] == 'application%2Foffset%2Boctet-stream':
              request.META['CONTENT_TYPE'] = 'application/offset+octet-stream'
  
          response = self.get_response(request)
          return response

This may be a bug on the Filepond side of the fence, but figured I'd report here in case anyone else has this issue.

@jcohen02
Copy link
Collaborator

Hi, thanks for highlighting this issue. I'll try to find some time to investigate this in the next couple of days.

It sounds like something may possibly have changed on the Filepond client side - glad you managed to work around this with some middleware but it should certainly work without that and certainly did previously so it looks like maybe a fix is required here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants