Uploading Files to WebDAV Server in AJAX Application
Due to modern browsers limitations there is no way to upload a file from local file system to WebDAV server using PUT verb as WebDAV specification requires. This article describes how to upload a file to IT Hit WebDAV Server engine using POST request.
Uploading using POST Multipart Request
While most WebDAV client upload files using PUT verb, AJAX/HTML applications are unable to submit a file using PUT. However the IT Hit WebDAV Server Engine can process files submitted with POST multipart request. The following example uploads a file to /mydocs folder:
<html>
<head><title>POST Upload to WebDAV Server</title></head>
<body>
<form action="/mydocs/" method="post" enctype="multipart/form-data">
<input type="file" name="dummyname" /><br />
<input type="submit" />
</form>
</body>
</html>
When creating a multipart POST form make sure you follow this rules:
- Specify enctype="multipart/form-data" attribute on a form tag.
- Add name attribute to a single input type=file tag.
- DO NOT add name attribute to any other input, select, textarea tags.
Always submit only one file per form. The server will be unable to calculate file size correctly if any extra input/select/textarea values submitted due to POST request standard limitations.
Action attribute can specify a folder or a file url. If the file with such name does not exist it will be created. If the file already exists it will be overwritten.
Note that maximum file upload size in most browsers is 2Gb.
|