The submitted file is empty - Error

Hi guys, as the title shows, I’m getting the error The submitted file is empty.. I’ve tried basically everything that I’ve found in this forum but nothing works. If I print out the request, this is what I’m getting: FILES: <MultiValueDict: {'file': [<InMemoryUploadedFile: untitled.glb (application/octet-stream)>]}> POST: <QueryDict: {'csrfmiddlewaretoken': ['XLsVQZRXD7Yf726r9vzeKEXze6cfAujP0KyD9xUhSWcB9wELwO5f6ubfiL7bJk4T'], 'name': ['Testa treno'], 'scala': ['1']}>. I’ll attach my code here:
Model:

def model_file_path(instance, filename):
    return f"models/{instance.id}/model.glb"

class ThreeDModel(models.Model):
    # Generate a unique folder identifier for each model.
    unique_folder = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
    name = models.CharField(max_length=128)
    # The GLB file will always be saved as 'model.glb' in the model's unique folder.
    file = models.FileField(upload_to=model_file_path)
    print(file)
    # Optionally, add a thumbnail field that stores images inside an 'img' folder.
    # thumbnail = models.ImageField(upload_to=threedmodel_thumbnail_upload_to, blank=True, null=True)
    scala = models.FloatField(blank=False, null=False, default=1.0)

    user = models.ForeignKey(
        UserProfile,
        on_delete=models.CASCADE,
        verbose_name="User"
    )

    project = models.ForeignKey(
        Project,
        on_delete=models.CASCADE,
        verbose_name="Project"
    )

    def __str__(self):
        return self.name

View:

class ThreeDModelCreateView(LoginRequiredMixin, CreateView):
    model = ThreeDModel
    form_class = ThreeDModelForm
    template_name = 'model/threedmodel_create.html'

    def dispatch(self, request, *args, **kwargs):
        self.project = get_object_or_404(
            Project,
            pk=self.kwargs['project_pk'],
            azienda=request.user.profile.azienda
        )
        return super().dispatch(request, *args, **kwargs)

    def form_valid(self, form):
        # Save the instance with commit=False to set project/user
        obj = form.save(commit=False)
        obj.project = self.project
        obj.user = self.request.user.profile
        # Save the instance to generate an ID
        obj.save()

        # Now save the file using the FileField's save method
        file = self.request.FILES['file']
        obj.file.save(file.name, file, save=True)

        return super().form_valid(form)

    def get_success_url(self):
        return reverse_lazy('project_dashboard', kwargs={'pk': self.project.pk})

Form

class ThreeDModelForm(forms.ModelForm):
    class Meta:
        model = ThreeDModel
        fields = ['name', 'file', 'scala']

    def __init__(self, *args, **kwargs):
        self.project = kwargs.pop('project', None)
        self.user = kwargs.pop('user', None)
        super().__init__(*args, **kwargs)

    def save(self, commit=True):
        instance = super().save(commit=False)
        instance.project = self.project
        instance.user = self.user
        if commit:
            instance.save()
        return instance

HTML:

{% extends "base.html" %}

{% block title %}Create 3D Model{% endblock %}

{% block content %}
<div class="container mt-4">
    <h2>Create New 3D Model for project: {{ project.name }}</h2>
<form method="post" enctype="multipart/form-data">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit" class="btn btn-primary">Create 3D Model</button>
</form>
</div>
{% endblock %}

EDIT 1:
I’ve discovered that the files are uploaded to the media folder rather then the static folder (and pushed into the database), for some reason which is in line with what the DjangoDocs says about the “The submitted file is empty.”:

newforms validation error comes up because there is an inconsistency in UploadedFile and InMemoryUploadedFile argument order.
Compare lines 23, 142, and 143 of ​django/django/core/files/uploadedfile.py at main · django/django · GitHub

Little note: the file that are being saved and are not returning the error are PDF and other random files, but when I upload a glb file, the error comes up.
This is my settings.py root and url section:

MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATIC_URL = '/static/'

When does the error come up? When you’re saving the file? When you’re linking to it (if so, using what view and template code)?

What is the full error message with the traceback?

Yes, uploaded files are “Media” files, not “Static” files, so should always end up in the Media directory.

The FileField will save the path to the uploaded file’s location within the Media directory, if that’s what you mean?

Can you provide a link to which part of the “DjangoDocs” your quote comes from?

Note - there is no need for you to explicitly do this. In fact, I believe this is the root cause of the problem

See the example at Handling uploaded files with a model. When using a model form, Django handles the physical file for you.

Also be aware that when saving uploaded files, you do not typically assign the physical file names for the files as they exist in the file system. (You can, but there are many reasons why you may not want to.) If you need to track an “original” file name as it was supplied by the user, then you can create an additional CharField to save that information. Otherwise, your only reference to that file would be through the model field containing the reference to it.

Side note: There’s also an inconsistency between your form_valid method in ThreeDModelCreateView and your save method in ThreeDModelForm.

and

Finally, to re-emphasize @philgyford 's reply above, uploaded files are not static files. They are completely independent from, and managed and referenced separately from static files. The two use concepts and constructs that are different.