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 = @"https://192.168.8.93:443/DCS_iOS/UploadedImages/luffy.jpg";
        //DownloadConfig.header = nil;
        
        [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 percents done", progress);return YES;}];

    @objc func IODownloadAsync() {
        var config=DcsHttpDownloadConfig()
        config.url="https://192.168.8.93:443/DCS_iOS/UploadedImages/luffy.jpg"
        dcsView.io.downloadAsync(config, mode: DME_IMAGE, successCallback: { (data) in
            print("successful")
        }, failureCallback: { (exp) in
            print(exp)
        }) { (progress) -> 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.