def test_get_endpoint(self): self.assertEqual("test", Client.get_endpoint("test", False, "")) self.assertEqual( "test-internal.endpoint", Client.get_endpoint("test.endpoint", False, "internal")) self.assertEqual("oss-accelerate.aliyuncs.com", Client.get_endpoint("test", True, "accelerate"))
def segment_video_body_advance(self, request, runtime): # Step 0: init client access_key_id = self._credential.get_access_key_id() access_key_secret = self._credential.get_access_key_secret() auth_config = _rpc_models.Config( access_key_id=access_key_id, access_key_secret=access_key_secret, type="access_key", endpoint="openplatform.aliyuncs.com", protocol=self._protocol, region_id=self._region_id ) auth_client = OpenPlatformClient(auth_config) auth_request = open_platform_models.AuthorizeFileUploadRequest( product="videoseg", region_id=self._region_id ) auth_response = auth_client.authorize_file_upload_with_options(auth_request, runtime) # Step 1: request OSS api to upload file oss_config = _oss_models.Config( access_key_id=auth_response.access_key_id, access_key_secret=access_key_secret, type="access_key", endpoint=RPCUtilClient.get_endpoint(auth_response.endpoint, auth_response.use_accelerate, self._endpoint_type), protocol=self._protocol, region_id=self._region_id ) oss_client = OSSClient(oss_config) file_obj = file_form_models.FileField( filename=auth_response.object_key, content=request.video_url_object, content_type="" ) oss_header = _oss_models.PostObjectRequestHeader( access_key_id=auth_response.access_key_id, policy=auth_response.encoded_policy, signature=auth_response.signature, key=auth_response.object_key, file=file_obj, success_action_status="201" ) upload_request = _oss_models.PostObjectRequest( bucket_name=auth_response.bucket, header=oss_header ) oss_runtime = ossutil_models.RuntimeOptions( ) RPCUtilClient.convert(runtime, oss_runtime) oss_client.post_object(upload_request, oss_runtime) # Step 2: request final api segment_video_bodyreq = videoseg_20200320_models.SegmentVideoBodyRequest( ) RPCUtilClient.convert(request, segment_video_bodyreq) segment_video_bodyreq.video_url = "http://" + str(auth_response.bucket) + "." + str(auth_response.endpoint) + "/" + str(auth_response.object_key) + "" segment_video_body_resp = self.segment_video_body(segment_video_bodyreq, runtime) return segment_video_body_resp
def detect_skin_disease_advance(self, request, runtime): # Step 0: init client access_key_id = self._credential.get_access_key_id() access_key_secret = self._credential.get_access_key_secret() auth_config = rpc_models.Config(access_key_id=access_key_id, access_key_secret=access_key_secret, type="access_key", endpoint="openplatform.aliyuncs.com", protocol=self._protocol, region_id=self._region_id) auth_client = OpenPlatformClient(auth_config) auth_request = open_platform_models.AuthorizeFileUploadRequest( product="imageprocess", region_id=self._region_id) auth_response = open_platform_models.AuthorizeFileUploadResponse() oss_config = oss_models.Config(access_key_secret=access_key_secret, type="access_key", protocol=self._protocol, region_id=self._region_id) oss_client = None file_obj = file_form_models.FileField() oss_header = oss_models.PostObjectRequestHeader() upload_request = oss_models.PostObjectRequest() oss_runtime = ossutil_models.RuntimeOptions() RPCUtilClient.convert(runtime, oss_runtime) detect_skin_diseasereq = imageprocess_20200320_models.DetectSkinDiseaseRequest( ) RPCUtilClient.convert(request, detect_skin_diseasereq) auth_response = auth_client.authorize_file_upload_with_options( auth_request, runtime) oss_config.access_key_id = auth_response.access_key_id oss_config.endpoint = RPCUtilClient.get_endpoint( auth_response.endpoint, auth_response.use_accelerate, self._endpoint_type) oss_client = OSSClient(oss_config) file_obj = file_form_models.FileField( filename=auth_response.object_key, content=request.url_object, content_type="") oss_header = oss_models.PostObjectRequestHeader( access_key_id=auth_response.access_key_id, policy=auth_response.encoded_policy, signature=auth_response.signature, key=auth_response.object_key, file=file_obj, success_action_status="201") upload_request = oss_models.PostObjectRequest( bucket_name=auth_response.bucket, header=oss_header) oss_client.post_object(upload_request, oss_runtime) detect_skin_diseasereq.url = "http://" + str( auth_response.bucket) + "." + str( auth_response.endpoint) + "/" + str( auth_response.object_key) + "" detect_skin_disease_resp = self.detect_skin_disease( detect_skin_diseasereq, runtime) return detect_skin_disease_resp
def image_blind_pic_watermark_advance(self, request, runtime): # Step 0: init client access_key_id = self._credential.get_access_key_id() access_key_secret = self._credential.get_access_key_secret() auth_config = _rpc_models.Config(access_key_id=access_key_id, access_key_secret=access_key_secret, type="access_key", endpoint="openplatform.aliyuncs.com", protocol=self._protocol, region_id=self._region_id) auth_client = OpenPlatformClient(auth_config) auth_request = open_platform_models.AuthorizeFileUploadRequest( product="imageenhan", region_id=self._region_id) auth_response = auth_client.authorize_file_upload_with_options( auth_request, runtime) # Step 1: request OSS api to upload file oss_config = _oss_models.Config( access_key_id=auth_response.access_key_id, access_key_secret=access_key_secret, type="access_key", endpoint=RPCUtilClient.get_endpoint(auth_response.endpoint, auth_response.use_accelerate, self._endpoint_type), protocol=self._protocol, region_id=self._region_id) oss_client = OSSClient(oss_config) file_obj = file_form_models.FileField( filename=auth_response.object_key, content=request.origin_image_urlobject, content_type="") oss_header = _oss_models.PostObjectRequestHeader( access_key_id=auth_response.access_key_id, policy=auth_response.encoded_policy, signature=auth_response.signature, key=auth_response.object_key, file=file_obj, success_action_status="201") upload_request = _oss_models.PostObjectRequest( bucket_name=auth_response.bucket, header=oss_header) oss_runtime = ossutil_models.RuntimeOptions() RPCUtilClient.convert(runtime, oss_runtime) oss_client.post_object(upload_request, oss_runtime) # Step 2: request final api image_blind_pic_watermarkreq = imageenhan_20190930_models.ImageBlindPicWatermarkRequest( ) RPCUtilClient.convert(request, image_blind_pic_watermarkreq) image_blind_pic_watermarkreq.origin_image_url = "http://" + str( auth_response.bucket) + "." + str( auth_response.endpoint) + "/" + str( auth_response.object_key) + "" image_blind_pic_watermark_resp = self.image_blind_pic_watermark( image_blind_pic_watermarkreq, runtime) return image_blind_pic_watermark_resp