The page that you are on when editing the node is something like: editContent.aspx?id=1071
So first you would get the nodes ID from the querystring like you would on any other webpage.
So to get the ID from the mediapicker you could do this:
Code:
//Get current node ID
int currentnode = int.Parse(System.Web.HttpContext.Current.Request.QueryString("id"));
//Create the node object
umbraco.presentation.nodeFactory.Node n = new umbraco.presentation.nodeFactory.Node(currentnode);
//Get the media ID
int mediaid = n.GetProperty("yourMediaPickerAlias");
This will of course depend on the node being published, so the process would be something like:
1: You open the page in umbraco
2: You select the media
3: Publish the node
4: Press the button in your custom datatype.
Is this the way you wanted to do it?