2
2
import logging
3
3
import mimetypes
4
4
import time
5
- import typing
6
5
import urllib
7
6
import urllib .parse
8
7
import warnings
@@ -247,15 +246,15 @@ def upload_file_to_s3(self, project_id: str, file_path: str, content_type: Optio
247
246
# content_type を推測
248
247
new_content_type = self ._get_content_type (file_path , content_type )
249
248
with open (file_path , 'rb' ) as f :
250
- return self .upload_file_object_to_s3 (project_id , fp = f , content_type = new_content_type )
249
+ return self .upload_data_to_s3 (project_id , data = f , content_type = new_content_type )
251
250
252
- def upload_file_object_to_s3 (self , project_id : str , fp : typing . IO , content_type : str ) -> str :
251
+ def upload_data_to_s3 (self , project_id : str , data : Any , content_type : str ) -> str :
253
252
"""
254
- createTempPath APIを使ってアップロード用のURLとS3パスを取得して、"file object" をアップロードする。
253
+ createTempPath APIを使ってアップロード用のURLとS3パスを取得して、"data" をアップロードする。
255
254
256
255
Args:
257
256
project_id: プロジェクトID
258
- fp: アップロードするファイルのfile object
257
+ data: アップロード対象のdata. ``requests.put`` メソッドの ``data``引数にそのまま渡す。
259
258
content_type: アップロードするfile objectのMIME Type.
260
259
261
260
Returns:
@@ -271,7 +270,7 @@ def upload_file_object_to_s3(self, project_id: str, fp: typing.IO, content_type:
271
270
s3_url = content ["url" ].split ("?" )[0 ]
272
271
273
272
# アップロード
274
- res_put = self .api .session .put (s3_url , params = query_dict , data = fp , headers = {'content-type' : content_type })
273
+ res_put = self .api .session .put (s3_url , params = query_dict , data = data , headers = {'content-type' : content_type })
275
274
276
275
annofabapi .utils .log_error_response (logger , res_put )
277
276
annofabapi .utils .raise_for_status (res_put )
@@ -838,18 +837,16 @@ def upload_instruction_image(self, project_id: str, image_id: str, file_path: st
838
837
"""
839
838
new_content_type = self ._get_content_type (file_path , content_type )
840
839
with open (file_path , 'rb' ) as f :
841
- return self .upload_file_object_as_instruction_image (project_id , image_id , fp = f ,
842
- content_type = new_content_type )
840
+ return self .upload_data_as_instruction_image (project_id , image_id , data = f , content_type = new_content_type )
843
841
844
- def upload_file_object_as_instruction_image (self , project_id : str , image_id : str , fp : typing .IO ,
845
- content_type : str ) -> str :
842
+ def upload_data_as_instruction_image (self , project_id : str , image_id : str , data : Any , content_type : str ) -> str :
846
843
"""
847
- file objectを作業ガイドの画像としてアップロードする 。
844
+ data を作業ガイドの画像としてアップロードする 。
848
845
849
846
Args:
850
847
project_id: プロジェクトID
851
848
image_id: 作業ガイド画像ID
852
- fp: アップロードするファイルのfile object
849
+ data: アップロード対象のdata. ``requests.put`` メソッドの ``data``引数にそのまま渡す。
853
850
content_type: アップロードするファイルのMIME Type.
854
851
855
852
Returns:
@@ -866,7 +863,7 @@ def upload_file_object_as_instruction_image(self, project_id: str, image_id: str
866
863
s3_url = content ["url" ].split ("?" )[0 ]
867
864
868
865
# アップロード
869
- res_put = self .api .session .put (s3_url , params = query_dict , data = fp , headers = {'content-type' : content_type })
866
+ res_put = self .api .session .put (s3_url , params = query_dict , data = data , headers = {'content-type' : content_type })
870
867
annofabapi .utils .log_error_response (logger , res_put )
871
868
annofabapi .utils .raise_for_status (res_put )
872
869
return content ["path" ]
0 commit comments