     success: (data, status, xhr) ->
       privateUrl = data.private_url
       publishEvent "upload:success", { uuid: uuid }
+      if privateUrl == null
+        displayFailedUpload(progressColumn)
+      else
+        fileColumn.html("<a href='#{privateUrl}'>#{filename}</a>")
+
+        virtualAttr = "#{container.data('parentType')}[new_#{container.data('association')}_uuids]"
+        hiddenField = "<input type='hidden' name='#{virtualAttr}[]' value='#{uuid}' />"
+        container.append(hiddenField)
     error: (xhr) ->
       console.log xhr.responseText
 

          if xhr.status == 201
            contentType = file.type
            publicUrl = $("Location", xhr.responseXML).text()
            privateUrl = saveUrl(container, uuid, fileName, contentType, publicUrl)

            if privateUrl == null
              displayFailedUpload(progressColumn)
            else
              fileColumn.html("<a href='#{privateUrl}'>#{fileName}</a>")

              virtualAttr = "#{container.data('parentType')}[new_#{container.data('association')}_uuids]"
              hiddenField = "<input type='hidden' name='#{virtualAttr}[]' value='#{uuid}' />"
              container.append(hiddenField)

          else
            displayFailedUpload(progressColumn)
            console.log $("Message", xhr.responseXML).text()

  ev.initCustomEvent name, true, false, detail
  document.dispatchEvent ev

saveUrl = (container, uuid, filename, contentType, publicUrl, progressColumn, fileColumn) ->
  privateUrl = null

  $.ajax
    type: "POST"
    url: "/s3_relay/uploads"
    data:
      parent_type: container.data("parentType")
      parent_id: container.data("parentId")
