Use the correct protocol for S3 attachment URLs based on the request security level

**Problem**: the generated URL for S3 attachments always uses the HTTP protocol. In the context of secure requests (made over HTTPS), the generated URL should use the HTTPS protocol instead.

**Solution**: Chosing the URL protocol during persistence of the attachment is not ideal because the attachment may be used in secured and unsecured contexts later. The correct protocol should be determined during the URL generation. This patch replaces the HTTP protocol and removes the port (:80) from the generated URL whenever the request is secure.