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.


- (void) uploadAsync: (NSArray *)indices
uploadConfig: (DcsHttpUploadConfig *) config
encodeParameter: (DcsEncodeParameter *) parameter
successCallback: (onUploadSuccess) onSuccess
failureCallback: (onUploadFailure) onFailure
progressUpdateCallback:(onUploadProgress) onProgress


indices:NSArray The indices of 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 The length of indices Expected result
DcsPNGEncodeParameter > 1 Upload the images as multiple PNG files.
DcsJPEGEncodeParameter > 1 Upload the images as multiple JPG files.
DcsPDFEncodeParameter > 1 Upload the images as a multi-page PDF.

For version 2.0 or earlier, if the length of indices is larger than 1, only the first image will be saved as a PNG/JPG file when the value of encodeParameter is DcsPNGEncodeParameter or DcsJPEGEncodeParameter.


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
void (^onUploadSuccess) (NSData *data)
Description This event is triggered when uploadAsync function is successfully executed.
Parameter data: The returned data message when uploadAsync function is successfully executed.
void (^onUploadFailure) (id userData, DcsException *exception)
Description This event is triggered when uploadAsync function is not successfully executed.
Parameter exception: The exception uploadAsync throws.
BOOL (^onUploadProgress) (NSInteger progress)
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.


NSMutableArray *IndexArr = [[NSMutableArray alloc] init];
for(NSInteger i = 0;i < [self.dcsView.buffer count];i++){
    NSNumber *num = [NSNumber numberWithInteger:i];
    [IndexArr addObject:num];
NSArray *UploadIndices = [IndexArr copy];
DcsHttpUploadConfig *uploadConf = [[DcsHttpUploadConfig alloc]init];
uploadConf.url = @"your upload url"; //Sets the url of the action page. Please change it to your own.
uploadConf.name = @"RemoteFile";  //Sets the name/key for the uploaded image data. The default value is 'name'.
uploadConf.uploadMethod = DUME_POST; //Sets the upload method to POST.
uploadConf.dataFormat = DDFE_BINARY; //Sets the data format to binary.
uploadConf.filePrefix = @"Dynamsoft";      //Sets the prefix of the file name. The default value is nil.
DcsPDFEncodeParameter *PdfEncode = [[DcsPDFEncodeParameter alloc]init];
NSData *response = [[NSData alloc]init];
[dcsView.io uploadAsync:UploadIndices uploadConfig:uploadConf encodeParameter:PdfEncode
     successCallback:^(NSData* data){NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];NSLog(@"UploadAsync succeeds! data: %@", str);}
                   failureCallback:^(id userData, DcsException *exception){NSLog(@"UploadAsync fails with exception: %@,%@", exception.name, exception.reason);NSLog(@"UploadAsync fail with userdata: %@", userData);}
                   progressUpdateCallback:^BOOL(NSInteger progress){NSLog(@"UploadAsync on going with %ld percent done", progress);return YES;}];

See also

How to upload images/documents to the web server

Is this page helpful?

Leave a Reply

Your email address will not be published.