Uploads images asynchronously. The selected image data in DcsBuffer will be encoded according to the value of encodeParameter and uploaded to the specified HTTP server.


func uploadAsync (indice:[Any], config:DcsHttpUploadConfig, parameter:DcsEncodeParameter, onSuccess:onUploadSuccess, onFailure:onUploadFailure, onProgress:onUploadProgress)


indices:[Any] An index array for images to be uploaded.
config:DcsHttpUploadConfig Configuration for HTTP upload.
parameter:DcsEncodeParameter Its value will be chosen from DcsPNGEncodeParameter, DcsJPEGEncodeParameter or DcsPDFEncodeParameter which represents to save the images as PNG, JPG or PDF files.
onSuccess:onUploadSuccess The callback function when this method performs successfully.
onFailure:onUploadFailure The callback function when this method performs unsuccessfully.
onProgress:onUploadProgress The callback function when this method pushes load progress information.

Return value



encodeParameter Maximum Value Result if the value exceeds the maximum value
DcsPNGEncodeParameter 1 Upload the first image as PNG file.
DcsJPEGEncodeParameter 1 Upload the first image as JPG file.
DcsPDFEncodeParameter no limit Upload the images as multi-page PDF.


Circumstance Exception thrown via onFailure callback
License verification failed. DcsLicenseVerificationFailedException
Upload fails due to the network issue. DcsHttpErrorException
No network connection. DcsNetworkDisconnectedException
Indices/encodeParameter/file is nil. DcsValueNotValidException
Indices include a value not smaller than DcsBuffer.count. DcsValueOutOfRangeException
The file size exceeded the 50MB limit. DcsException
typealias onUploadSuccess = (data: Data) -> Void
Description This event is triggered when uploadAsync function is successfully executed.
Parameter data: The returned data message when uploadAsync function is successfully executed.
typealias onUploadFailure = (userData:Any exception: DcsException) -> Void
Description This event is triggered when uploadAsync function is not successfully executed.
Parameter exception: The exception uploadAsync throws.
onUploadProgress = (progress: Int)-> Bool
Description This event is triggered when uploadAsync function is executing and showing the progress.
Parameter progress: The progress of uploading.
Return When YES is returned, uploadAsync will keep executing. When NO is returned, uploadAsync will stop.


class ViewController: UIViewController{
    var dcsView:DcsView!
    override func viewDidLoad() {
        dcsView = DcsView(frame: CGRect(x:0,y:0,width:self.view.frame.size.width,height:self.view.frame.size.height))
        let uploadConfig = DcsHttpUploadConfig()
        let dcsPDFEncodeParameter = DcsPDFEncodeParameter()
        uploadConfig.url = "<Your upload url>"
        uploadConfig.uploadMethod = DUME_POST
        uploadConfig.dataFormat = DDFE_BINARY
        var indexArray = Array<Int>()
        for index in 0...dcsView.buffer.count()-1
        dcsView.io.uploadAsync(indexArray, uploadConfig: uploadConfig, encodeParameter: dcsPDFEncodeParameter,
        successCallback: {(receive: Data) in 
            print("Success.",String(data: receive!, encoding: .utf8))
        },failureCallback: {(userData: Any, exp: DcsException!) in
        }){(progress: Int) -> Bool in
            return true
            //If false is returned, the action will be cancelled.

See also

How to upload images/documents to the web server

Is this page helpful?