Fix cast exception when building a multipart request