Skip to content

Commit f81b0ae

Browse files
authored
Merge pull request #138 from kurusugawa-computer/modify-upload-file-method-name
`upload_file_object_XXX`メソッドの名前を変更
2 parents 61c0b86 + bb4c11b commit f81b0ae

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

annofabapi/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.27.10'
1+
__version__ = '0.27.11'

annofabapi/wrapper.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import logging
33
import mimetypes
44
import time
5-
import typing
65
import urllib
76
import urllib.parse
87
import warnings
@@ -247,15 +246,15 @@ def upload_file_to_s3(self, project_id: str, file_path: str, content_type: Optio
247246
# content_type を推測
248247
new_content_type = self._get_content_type(file_path, content_type)
249248
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)
251250

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:
253252
"""
254-
createTempPath APIを使ってアップロード用のURLとS3パスを取得して、"file object"をアップロードする。
253+
createTempPath APIを使ってアップロード用のURLとS3パスを取得して、"data" をアップロードする。
255254
256255
Args:
257256
project_id: プロジェクトID
258-
fp: アップロードするファイルのfile object
257+
data: アップロード対象のdata. ``requests.put`` メソッドの ``data``引数にそのまま渡す。
259258
content_type: アップロードするfile objectのMIME Type.
260259
261260
Returns:
@@ -271,7 +270,7 @@ def upload_file_object_to_s3(self, project_id: str, fp: typing.IO, content_type:
271270
s3_url = content["url"].split("?")[0]
272271

273272
# アップロード
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})
275274

276275
annofabapi.utils.log_error_response(logger, res_put)
277276
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
838837
"""
839838
new_content_type = self._get_content_type(file_path, content_type)
840839
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)
843841

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:
846843
"""
847-
file objectを作業ガイドの画像としてアップロードする
844+
data を作業ガイドの画像としてアップロードする
848845
849846
Args:
850847
project_id: プロジェクトID
851848
image_id: 作業ガイド画像ID
852-
fp: アップロードするファイルのfile object
849+
data: アップロード対象のdata. ``requests.put`` メソッドの ``data``引数にそのまま渡す。
853850
content_type: アップロードするファイルのMIME Type.
854851
855852
Returns:
@@ -866,7 +863,7 @@ def upload_file_object_as_instruction_image(self, project_id: str, image_id: str
866863
s3_url = content["url"].split("?")[0]
867864

868865
# アップロード
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})
870867
annofabapi.utils.log_error_response(logger, res_put)
871868
annofabapi.utils.raise_for_status(res_put)
872869
return content["path"]

0 commit comments

Comments
 (0)