Managing Files and Folders with WebDAV > Uploading a File or Directory
Uploading a File or Directory
Internal WebDAV
Upload a file or directory to the portal.
Object URI
File upload: {INT_WEBDAV_URL}/File_path
Directory upload: {INT_WEBDAV_URL}/Dir_path
HTTP Method
POST
Request Content-Type
multipart/form-data
Request Headers
Overwrite=T/F – Set to T if you want to overwrite an existing file or F, the default, not to overwrite the file
Boundary=boundary – a user defined value that is used as the encapsulation boundary in the request body.
Request body example
boundary
Content-Disposition: form-data; name="Filename"
{file_name.extension}
 
boundary
Content-Disposition: form-data; name="fullpath"
{WEBDAV_URL}/Destination_path
 
boundary
Content-Disposition: form-data; name="filedata"
file_in_binary_format
Expected Response status
200 OK
If a response such as 412 Precondition Failed is returned, the operation was canceled due to Overwrite being set to False.
If a response such as 401 Access Denied is returned, check the permissions.
If a response such as 404 Not Found is returned, check the spelling of the URL.
If a response such as 403 Not Allowed is returned, the file is passphrase protected.
External WebDAV
The Java example below uses a put function that assumes overwrite=true. While it is possible to work with this preset configuration, you can also override this preset by changing the sardine client constructor. See Changing Sardine Client Constructor to Disallow Overwrite.
Java Example
To upload a file to a certain path, use:
// This example uses Apache Commons IO in order to read a file.
byte[] data = FileUtils.readFileToByteArray(new File(localPath));
sardine.put(EXT_WEBDAV_URL + "/" + path, data);