If you live in Shanghai for more than one year, you can apply for divorce in Shanghai, but you cannot apply for divorce by agreement.
Interpretation of the Supreme People's Court on Several Issues Concerning the Application of the Civil Procedure Law of the People's Republic of China
Article 12 A case in which one spouse has left his or her place of residence for more than one year and the other spouse brings a divorce suit may be under the jurisdiction of the people's court in the place where the plaintiff has his or her place of residence.
If both husband and wife have left their places of residence for more than one year and one party filed a lawsuit for divorce, the case shall be under the jurisdiction of the people's court of the defendant's habitual residence. If there is no habitual residence, the case shall be under the jurisdiction of the people's court of the defendant's habitual residence when the plaintiff filed the lawsuit.