         {withCredentials}
       success: (data) ->
         if @options.patch then @previouslySavedContent = data
+        metadata.name ?= data.docName
         callback null, new CloudContent data.content or data
       error: ->
         message = if metadata.sharedContentId


  # The document server requires the content to be JSON, and it must have
  # certain pre-defined keys in order to be listed when we query the list
  _wrapContent: (content, share) ->
    if isString content
      try
        content = JSON.parse content
      catch
    JSON.stringify
      appName: @options.appName
      appVersion: @options.appVersion
      appBuildNum: @options.appBuildNum
      content: content
      _permissions: if share then 1 else 0

  _createDiff: (json1, json2) ->
    try

      sendContent = diff
      url = patchDocumentUrl
    else
      if metadata.name and not isSharing then params.recordname = metadata.name
      url = saveDocumentUrl
      sendContent = content

