Download images/documents from the web

We can call our built-in HTTP download method to download the image(s) or document(s) asynchronously to DcsBuffer.

Format Method
PNG, JPEG, PDF downloadAsync() Swift, Objective-C

DcsHttpDownloadConfig *DownloadConfig = [DcsHttpDownloadConfig alloc];

DownloadConfig.url = @"<your download url>"; // Specifies the url of the image you want to download. Please change it to your own.
        
[dcsView.io downloadAsync:DownloadConfig mode:DME_IMAGE 
            successCallback:^(NSData* data){NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];NSLog(@"DownloadAsync succeeds! data: %@", str);} 
            failureCallback:^(DcsException *exception){NSLog(@"DownloadAsync fails with exception: %@,%@", exception.name, exception.reason);}
            progressUpdateCallback:^BOOL(NSInteger progress){NSLog(@"DownloadAsync on going with %ld percent done", progress);return YES;}];

    @objc func IODownloadAsync() {
        var config = DcsHttpDownloadConfig()
        config.url = "<your download url>" // Specifies the url of the image you want to download. Please change it to your own.
        dcsView.io.downloadAsync(config, mode: DME_IMAGE, successCallback: { (downloaddata: Data) in
            print("successful")
        }, failureCallback: { (exp: DcsException!) in
            print(exp.description)
        }) { (progress: Int) -> Bool in
            print(progress)
            return true
        }
    }

With the above code, the image will be downloaded into DcsBuffer as dcsImage.

This is especially useful when you want to review an image/a document created and uploaded by Dynamsoft Camera SDK.

Is this page helpful?

Leave a Reply

Your email address will not be published.