split uploadStream to two phases for web use