Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This field is required error #214

Unanswered
isik-kaplan asked this question in Q&A
Discussion options

With this simple setup:

direct_s3_storage = S3OptimizedUploadStorage()
class FileUpload(models.Model):
 file = models.FileField(storage=direct_s3_storage)
 
class CsvUploadForm(ModelForm):
 class Meta:
 model = FileUpload
 fields = ["file"]
class FileUploadView(FormView):
 form_class = FileUploadForm
 template_name = "upload.html"
<form method="post" enctype="multipart/form-data"> 
 {% csrf_token %}
 {{ form }}
</form>
{{ form.media.js }}

I keep getting File: This field is required.

When I add {{ form.media.js }} request.FILES is empty, and "file" in request.POST, when I remove the {{ form.media.js }} request.FILES has "file" and "file" not in request.POST

I have the app and the middleware.

I've tried to figure it out myself but couldn't. I feel like I'm missing something, but I'm not entire sure what. Should I initiate my form differently?

You must be logged in to vote

Replies: 2 comments

Comment options

Hi there,

Thanks for reaching out. You shouldn't need to use multipart/form-data, since you don't send the file via the form. However, I am curious, are you running this on S3 or local development?
I would recommend opening up the browser console and to look out for any errors. That information would be useful for me to help you with your problem.

Best,
Joe

You must be logged in to vote
0 replies
Comment options

I tried it with a fresh project that doesn't have any other middlewares and found out that the error was on my part, sorry. Probably should've tried to do that prior to opening an issue. Fixed the problem in my code and now it works. I have a different problem related to the progress bars, though. I'll create a new discussion for that. Thanks!

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #213 on April 20, 2022 11:34.

AltStyle によって変換されたページ (->オリジナル) /