Using a Pipeline to POST Data

Here is some sample code to post data results in a http client using Salesforce B2C Commerce script.
var httpSvc : HTTPClient = new HTTPClient(); "POST", "http://localhost/on/
httpSvc.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); httpSvc.send("data=aaaa");
The content type is important. Otherwise the request might not be decoded correctly on the target system and so it doesn't see any post data.

Allowing File Upload by Customers

This topic describes how to create a template and script to add the ability to upload files to the instance. This might be used, for example, for customers to upload their photo for customer profiles

First you need to create the template for the upload:

enctype="multipart/form-data" method="post" style="padding-left: 10px">
size="40" name="image" type="file" /> <input type="submit"
name="add" value="add" /> </form>The form encode type must be multipart/form-data
and the method must be post.

The script that does the upload

importPackage( dw.system ); 
importPackage( dw.web ); 
importPackage( ); 
importPackage( dw.util ); 

function execute( pdict : PipelineDictionary ) : Number { 
	var filename : String; 
	var params : HttpParameterMap = pdict.CurrentHttpParameterMap; 
	var files : LinkedHashMap = new LinkedHashMap(); //callback function
	var closure : Object = function(field, ct, oname){ 
		filename = oname; 
		return new File( File.IMPEX + "/" + oname);
	files = params.processMultipart(closure); 
	return PIPELET_NEXT; 

The variable closure is a callback function. The api calls the function, passing in the fieldname of the file input, the content type and the file name that was uploaded via the multipart form. This callback is passed into the processMultipart method. The return is a Map of the files that were uploaded.

The callback is called for each file that you upload. If you are uploading five files, the callback is called five times and the return Map contains all five file references.