Jump to content
corneliusdavid

Getting uploaded file from post data

Recommended Posts

I've got a small WebBroker application that requests the user to choose a file which is then posted to another page of the WebBroker application. The web form's HTML is like this:

 <form action="UploadFile" method="post" enctype="multipart/form-data">
  <label for="MyFile">Select file to upload:</label><br />
  <input type="file" id="MyFile">
  <button type="submit">Upload</button>
</form>

The TWebApplicationItem that handles the "/UploadFile" path is trying to get the file to upload so it can save it on the server but I can't find documentation or an example of how to do this.

 

I've tried looking at both TRequest.ContentFields and TRequest.Files properties but they're always empty. I found an old StackOverflow question relating to this that mentioned including the ReqMulti unit so that it parses the multi-part form but that didn't fill the Files property for me. Finally, I called Request.ExtractContentFields but it just gave me the same raw string, ('------WebKitFormBoundaryBRM3RcInbYBqzsVj--') that I saw in the TRequest.Content property. From what I've been reading, I should be able to create a TFileStream and somehow use the Content property to read the file from the headers but I'm not sure how to get the file information.

 

Can someone point me in the right direction?

Share this post


Link to post

Re-reading the StackOverflow question and looking more closely at my HTML, I realized I was missing the name attribute in the input element. Now my Files property is being filled and I can save the uploaded file. 🙂

<form action="UploadFile" method="post" enctype="multipart/form-data">
  <label for="MyFile">Select file to upload:</label><br />
  <input type="file" id="MyFile" name="MyFile">
  <button type="submit">Upload</button>
</form>

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×