WWDC21 SALE: Save 50% on all my Swift books and bundles! >>

Uploading files to a web server, securely

Forums > iOS

I'm working on a private app, not to the public, only one copy in exsistence. What I'm trying to attempt:

Create .json file -> Send .json file to webserver, but make the webserver require a username and password to accept the file.

I'm not talking about creating a login box with username and password. I'm more talking about sending a file to http://www.myWebsite.com/PlaceToPutFile%user:user%password:password kind of thing.

Alamofire seems good for the uploading part of it (I actually have that working, but no username or password is required, so anyone can send a file at this point). Anyone have a clue or a lead I can use on how to set up the server side, so the iOS side can send the file?

I've been stuck on this small piece for weeks. Buddy pointed me to WebDAV, but I can't seem to get Alamofire to work with that.


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

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

But no file has been uploaded.


Save money with our WWDC sale!

SAVE 50% To celebrate WWDC21, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.