Save a custom level or other shared content
save(type, content, callback, thumbnail, label)

Saving content

You can use the save function on the sharedContent property of the Kongregate API object to submit shared content on the Kongregate back-end. It accepts a type, content string, callback, and optionally a thumbnail and a label:

NameTypeDescription
typeStringType of content the user wishes to save, 12 characters max
contentStringValue of content to be saved. We strongly recommend keeping these values under 100K since the game will hang until the content is sent, which can lead to a poor user experience if the content is too large
callbackFunctionFunction to be called when the operation is completed
thumbnailDisplayObject or Base64-encoded stringOptional, but highly recommended! Send us a DisplayObject or Base64-encoded image string that we will snapshotted and used as a thumbnail for the content. If this is not provided we will take a picture of the entire stage and use that as the thumbnail (for AS3 games)
labelStringOptional label for sub-classing the shared content.

The callback method will be passed a single object with the following attributes:

NameTypeDescription
successBooleanFlag indicating whether or not the operation was successful
idIntegerUnique ID of the created shared content
nameStringName of the shared content
permalinkStringLink to the shared content
contentStringThe content itself
labelStringThe label for the shared content

Example: Save some shared content to as a Contraption with the contents x1y3z10, calling back onContraptionSaved using myContraptionEditor for the thumbnail and with the label Level 3 Solution

kongregate.sharedContent.save('Contraption', 'x1y3z10', onSaved,                         											 myContraptionEditor,'Level 3 Solution');

function onSaved(params:Object):void {
  if (params.success) {
    // The shared content was saved successfully.
    trace("Content saved, id:" + params.id + ", name:" + params.name);
  } else {
    // The shared content was not saved.
    // The most likely cause of this is that the User dismissed the save dialog  
  }
}
kongregate.sharedContent.save('Contraption', 'x1y3z10', onSaved,                         											 myContraptionEditor,'Level 3 Solution');

function onSaved(params) {
  if (params.success) {
    // The shared content was saved successfully.
    console.log("Content saved, id:" + params.id + ", name:" + params.name);
  } else {
    // The shared content was not saved.
    // The most likely cause of this is that the User dismissed the save dialog  
  }
}

Related: