UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

3      

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.

3      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.