In general these kinds of problems with pulleys are solved in the same way, so I'll provide an explanation so it's useful for others.
First, note that the length of the string is constant, and denote it by $L$. Now, let's divide it in four segments:
From the geometry of the figure, you may want to express the other lengths in function of known quantities.
Now if we take the derivative of the above expression,
Since you're interested in the upwards velocity, from the geometry of the problem you can clearly see that,
Since the problem says the segments $A$ and $B$ are moving downwards, then $v_A=v_B=-u$, so we finally get:
You were on the right track, however I think you got confused with the trigonometric identities, hence why you got the cosine on the wrong position.