Yes, but you need a proper permit to legaly stay in Canada while you wait. Filing the aplication while you're in the country doesn't give you permission to stay there.
Be prepared to wait a couple of years for it, at least. (check the processing times at Buffalo)