httpUploadAsync()

Description

Uploads images of specified indices in Dynamsoft image viewer to the HTTP server asynchronously .

Syntax

ImageViewerObject.io.httpUploadAsync(url, indices, imageType, onHttpUploadSuccess, onHttpUploadFailure[, onHttpUploading = null[, httpMethod = EnumHttpMethod.POST [, dataFormat = EnumUploadDataFormat.BINARY]]]));

Parameters

<string> url: specifies the name of the http server and action page and filename. For example “www.dynamsoft.com/ActionPageName?filename=FileName”
<int[]> indices: specifies the indices of images in buffer. The index is 0-based.
<EnumImageType> imageType: specifies the format of the file you want to upload as.

Image Type Enumerated Value
BMP EnumImageType.BMP
JPEG EnumImageType.JPEG
TIFF EnumImageType.TIFF
PNG EnumImageType.PNG
PDF EnumImageType.PDF

<onHttpUploadSuccess function> onHttpUploadSuccess: callback function triggered when the file is uploaded successfully.
<onHttpUploadFailure function> onHttpUploadFailure: callback function triggered when the file failed to be uploaded.
<onHttpUploading function> optional onHttpUploading: callback function triggered during uploading image.
<EnumHttpMethod> optional HttpMethod: specifies the uploading method, either EnumHttpMethod.POST or EnumHttpMethod.PUT.
<EnumUploadDataFormat> optional dataFormat: specifies the data format, either EnumUploadDataFormat.BINARY or EnumUploadDataFormat.BASE64.

Please refer to the function prototype onHttpUploadSuccess or onHttpUploadFailure or onHttpUploading.

Return value

void

Remarks

EnumImageType, EnumHttpMethod and EnumUploadDataFormat is under namespace io.

If imageType is EnumImageType.BMP/JPEG/PNG, the length of indices must be 1.

EnumHttpMethod.PUT is not supported in version 5.0 and 5.1.

For IE 9 or lower, even if you set data format to EnumUploadDataFormat.BINARY, this setting will be ignored and the image will be automatically uploaded as BASE64 format.

Example

var imageviewer = DCSObject.getImageViewer("******");  // Get a specified image viewer
imageviewer.io.httpUploadAsync("https://www.dynamsoft.com/SaveToFile.aspx?filename=001.pdf", [0,1], imageviewer.io.EnumImageType.PDF, onHttpUploadSuccess, onHttpUploadFailure, onhttpdownloading, imageviewer.io.EnumHttpMethod.POST, imageviewer.io.EnumUploadDataFormat.BINARY);

function onHttpUploadSuccess (httpResponse) {
    console.log("HTTPResponseString: " + httpResponse);
}

function onHttpUploadFailure (errorCode, errorString, httpResponse) {
    console.log("ErrorCode: " + errorCode+ "ErrorString: " + errorString + "HTTPResponseString: " + httpResponse);
}

function onhttpdownloading (percentage) {

}

See also

.io.httpUpload()

.io.httpDownload()