It is fairly common, and certainly not illegal, for two intimate partners to make an explicit recording of themselves, as long as they are both aware of this and consent to the activity. It is illegal to record someone without their knowledge, of course, but many people will do this intentionally.
However, if you have control of an explicit video that contains someone else, posting that video on the internet could lead to serious criminal charges. The fact that you initially created the video or are even in it does not change this. You may be charged under revenge porn laws if the other party did not know that you were posting the video, and especially if you are simply doing it as a form of cyberbullying, trying to harass them or simply expose a video that they would’ve liked to keep private.
Is there any way to do it legally?
You certainly can put this type of content online if you would like. Some people do it on websites where they are paid for the content, so it’s a form of income. It is not illegal in every case.
But the key is consent. It’s one thing for two consenting adults to agree to make a video or to put it on the internet, because they have both signified that this is something they would like to do. They’re choosing it intentionally. But consent is required from both parties, not just one. Even if the video is on your phone or your computer, if it contains someone else, you also need to have their consent to show anyone else that video.
If you are facing charges, perhaps after accidentally uploading something without realizing the ramifications, be sure you know what legal steps to take.