1

Okay, so I was having a weird file upload problem. I had some code set up like this on the cshtml file.

<form method="post" action="~/meme/createcustom2"  id="submitimage" name="submitimage">
        <div class="drag-box">
            <div class="drag">
                <div id="dragandrophandler">
                    <label class="hand">
                        Drag File or
                        Click to Upload&hellip;
                        <input type="file" id="uploadFile" name="uploadFile">                        </label>
                </div>
            </div>
            <span class="or">Or</span>
            <span class="uploadBtn" id="uploadBtn">
                <a href="#" class="btn">UPLOAD <i class="fa fa-upload" aria-hidden="true"></i></a>
            </span>
            <p>Choose an image from your computer</p>
        </div>

And no matter what I did, the file wasn't uploading. I'd see the entry in the Forms collection, but no entry in the Files collection. Well, that vexed me this entire morning.

What am I missing?

1 Answer 1

8

There are a lot of questions like this, and most answers suggesting changing the input tag's name attribute, that might help in some cases, but this is not why the problem occurs.

I could find it after a little hunting.

My form tag is missing the following attribute

enctype="multipart/form-data"

This attribute is needed before the form will accept binary files. Otherwise it only accepts uuencoded text data.

I put that in, and changed my form tag to look like this

<form method="post" action="~/meme/createcustom2" enctype="multipart/form-data" id="submitimage" name="submitimage">

That solved the problem.

Hope it helps someone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.