I have a Django backend (using Django REST Framework), and a SvelteKit frontend that talks to it. Everything works perfectly fine in all browsers across Windows and macOS, all POST and DELETE requests and all that have the correct CORS headers.
Except the endpoint to upload images. That one doesn't seem to work for Windows users, in Edge, Chrome, or Firefox.
The endpoint uses Django REST Framework's APIView
, just like many other endpoints.
class ImageUploadParser(FileUploadParser):
media_type = "image/*"
def get_filename(self, stream, media_type, parser_context):
# We create our own filename, and we get the extension based on the actual file type
return "unused.nope"
class ImageUploadView(APIView):
permission_classes = (permissions.IsAuthenticated,)
parser_classes = [ImageUploadParser]
def post(self, request):
# [A bunch of logic to upload the file...]
return Response({"url": f"{relative_path}/{filename}"}, status=status.HTTP_201_CREATED)
I've set up corsheaders.middleware.CorsMiddleware
and its CORS_ALLOWED_ORIGINS
setting. Like I said, all other endpoints work fine, and the upload endpoint also works fine under macOS (Safari, Edge and Firefox).
This is the network inspector in Safari:
And this is Edge on Windows:
What could cause this one endpoint to not work, and only in Windows? How can I solve it?
i think it could be the difference in file size. in your Windows inspector says content-length: 1132500
and the Safari one says content-length: 86348
.
did you upload the same file?
references: about 413