Uploading a file to WebDAV server using AlamoFire

277 views Asked by At

I'm working on a private iOS14 app that will send files to a website server. User will just tap on a button, and the code will do all the work (hard coded username and password).

I would like to upload File.json to a WebDAV server (http://myWebsite.com/Files).
I would like to upload Image.png to a WebDAV server (http://myWebsite.com/Files). The server requires a username & password (username: username, password: password).

func UploadJson(){
    
    let username = "username"
    let password = "password"
    let credential = URLCredential(user: username, password: password, persistence: .forSession)
    
    let fileURL = Bundle.main.url(forResource: "File", withExtension: "json")!
    let http = "https://myWebiste.com/Files"

    AF.upload(fileURL, to: http)
        .authenticate(with: credential)
        .response { response in
            debugPrint(response)
        }
}

I get a [Response]: [Status Code]: 200

But no file has been uploaded.

I can use a Mac and login using the username and password and upload a file to the server, so I know the WebDAV folder is working. But the AlamoFire code isn't.

What am I missing? Do I need anything in the Files folder on the server to allow uploads? Currently it is empty.

0

There are 0 answers