Transferring files and form data

Home > Basic examples > Example 06

Explanation

DEXTUploadX5 does not provide policy to automatically transfer form data.

DEXTUploadX5 calls the callback function (onDX5UploadCompleted) after the file upload is complete. In this function, it is recommended to use a method of submitting form data of the form element separately from the file information received from the server. This method has the advantage that the service processing structure becomes clearer because the file and other string data can be completely separated and processed.

function transfer() {
	var dx = dx5.get("dext5");
	if (dx.hasUploadableItems()) {
		// If there are any files to upload, upload first.
		// When the upload is complete, the onDX5UploadCompleted callback function is called.
		// Configure the form data to be sent when the callback function is called.
		dx.upload("AUTO");
	} else {
		// Send the form data immediately because there is no object to upload.
		submit(null);
	}
}
// This is a callback function that is called when the upload is complete (server-side file upload processing is completed).
function onDX5UploadCompleted(id) {
	// Since it is ORAF, there is one unconditional response data.
	// Send the form data with this response data.
	submit(dx5.get(id).getResponses()[0]);  
}
function submit(response) {
	var formObj = document.getElementsByTagName("form")[0];
	
	// Set response data to hidden element.
	formObj.newFileKeys.value = response || "";
	
	// Submit the form data.
	formObj.submit();
}

In this structure, the file upload is processed by the "upload-serivce.ashx", and the form data is finally processed by the "form-process.ashx".

Example