Have you tried this instead? http://msdn.microsoft.com/en-us/library/websvcimaging.imaging.upload.aspx
I haven't really seen ECMAScript examples uploading files in SharePoint. Either use a Silverlight Control or one of the Web Services to handle content. Client Object Model comes in many shapes (Managed, ECMA and Silverlight - each with its own constraints and limitations).
Hope it helps, C:\Marius