Hallo,
ich möchte einen WebApplication-Server aufbauen der iOS-Swift URLSessions annehmen kann.
Ich möchte von meiner iOS-App Dateien up- und downloaden. Dazu hat Swift 5 die Befehle:
Hi there,
I want to set up a web application server that can accept iOS Swift URL sessions.
I would like to upload and download files from my iOS app. Swift 5 has the following commands:
session.uploadTask(with: request, from: imageData)
session.downloadTask(with: URL)
In Swift habe ich folgendes:
In Swift I have the following:
class SessionDelegate: NSObject, URLSessionDataDelegate {
func urlSession(_ session: URLSession, task: URLSessionTask, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) {
let progress = round(Float(totalBytesSent) / Float(totalBytesExpectedToSend) * 100)
print("progress: \\(progress) %")
}
}
let Btn03 = UIAlertAction(title: “uploadTask”, style: .default, handler: { (action) in
let image = UIImage(named: "LOGO GmbH")
let imageData = image?.jpegData(compressionQuality: 1.0)
let uploadURL = URL(string: "http://192.168.50.50:8080/api/register")!
var request = URLRequest(url: uploadURL)
request.httpMethod = "Post"
let session = URLSession(configuration: .default, delegate: SessionDelegate(), delegateQueue: OperationQueue.main)
let task = session.uploadTask(with: request, from: imageData) {
(data, response, error) in
let serverResponse = String(data: data!, encoding: .utf8)
print(serverResponse!)
}
task.resume()
})
progress: 18.0 %
progress: 37.0 %
progress: 55.0 %
progress: 74.0 %
progress: 92.0 %
progress: 100.0 %
register=true
Das Ergebnis ist, dass Die Datei ordentlich gesendet wird, und POST verarbeitet wird.
The result is that the file is sent properly and POST is processed.
#######################################
In der XOJO-App (WebApplication) habe ich in der HandleSpecialURL:
Ich kann leider die empfangene Datei oder Daten nicht finden, um diese dann z.B. als jpg zu speichern.
Ich Danke Euch für Eure Hilfe
In the XOJO app (WebApplication) I have in the HandleSpecialURL:
Unfortunately I cannot find the received file or data to e.g. save as jpg.
Thank you for your help
#####################################
In the XOJO app (WebApplication) I have in the HandleSpecialURL:
print "App.HandleSpecialURL "
print “App.HandleSpecialURL Request.Path=”+Request.Path
print “App.HandleSpecialURL Request.RemoteAddress=”+Request.RemoteAddress
print “App.HandleSpecialURL Request.Response=”+Request.Response
print “App.HandleSpecialURL Request.Status=”+Request.Status.ToString
print “App.HandleSpecialURL Request.Entity=”+Request.Entity
print “App.HandleSpecialURL Request.QueryString=”+Request.QueryString
Select Case Request.Path
Case “register”
print “register”
print " "
Var f As FolderItem
f = SpecialFolder.Documents //ApplicationData
If f <> Nil Then
print f.NativePath
// /Users/karsten/Documents
Else
print “There is no Application Data folder on this computer.”
End If
Var source As Picture
Var pictureFile As FolderItem
Var uploadFolder As FolderItem
uploadFolder = New FolderItem(“UploadFolder”)
If Not uploadFolder.Exists Then
uploadFolder.CreateAsFolder
End If
Request.Print(“register=true”)
Return True
Case “quote”
// Output a movie quote
Dim quote As String
quote = mQuote(Randomizer.InRange(0, mQuote.Ubound))
Request.Print("" + EndOfLine)
Request.Print("" + EndOfLine)
Request.Print("" + EndOfLine)
Request.Print(“Quote” + EndOfLine)
Request.Print("" + EndOfLine)
Request.Print("" + EndOfLine)
Request.Print(“
Your Quote
” + EndOfLine)Request.Print("
" + quote + “
” + EndOfLine)Request.Print("" + EndOfLine)
Request.Print("")
// Return true to signal that we handled the request
Return True
Case Else
// Don’t handle any other requests
Return False
End Select
Output of Console:
17:27:33 : App.HandleSpecialURL
App.HandleSpecialURL Request.Path=register
App.HandleSpecialURL Request.RemoteAddress=192.168.50.50
App.HandleSpecialURL Request.Response=
App.HandleSpecialURL Request.Status=200
App.HandleSpecialURL Request.Entity=???pp.HandleSpecialURL Request.QueryString=
register
/Users/karsten/Documents