PureBasic
PureBasic
Asynchronous HTTP Upload
See more Upload Examples
Demonstrates how to do an HTTP upload asynchronously in a background thread.A server-side C# example showing how to receive an upload is located at C# ASP.NET Code to Receive Upload
Chilkat PureBasic Downloads
IncludeFile "CkUpload.pb"
Procedure ChilkatExample()
success.i = 0
upload.i = CkUpload::ckCreate()
If upload.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Specify the page (ASP, ASP.NET, Perl, Python, Ruby, CGI, etc)
; that will process the HTTP Upload.
CkUpload::setCkHostname(upload, "www.mywebserver.com")
CkUpload::setCkPath(upload, "/receiveUpload.aspx")
; Add one or more files to be uploaded.
CkUpload::ckAddFileReference(upload,"file1","dude.gif")
CkUpload::ckAddFileReference(upload,"file2","pigs.xml")
CkUpload::ckAddFileReference(upload,"file3","sample.doc")
; Begin the HTTP upload in a background thread:
success = CkUpload::ckBeginUpload(upload)
If success <> 1
Debug CkUpload::ckLastErrorText(upload)
Else
Debug "Upload started..."
EndIf
; Wait for the upload to finish.
; Print the progress as we wait...
While (CkUpload::ckUploadInProgress(upload) = 1)
; We can abort the upload at any point by calling:
; upload.AbortUpload();
; Display the percentage complete and the number of bytes uploaded so far..
; The total upload size will become set after the upload begins:
Debug Str(CkUpload::ckPercentUploaded(upload)) + "% " + Str(CkUpload::ckNumBytesSent(upload)) + "/" + Str(CkUpload::ckTotalUploadSize(upload))
; Sleep 2/10ths of a second.
CkUpload::ckSleepMs(upload,200)
Wend
; Did the upload succeed?
If CkUpload::ckUploadSuccess(upload) = 1
Debug "Files uploaded!"
Else
Debug CkUpload::ckLastErrorText(upload)
EndIf
CkUpload::ckDispose(upload)
ProcedureReturn
EndProcedure