Skip to content

Commit

Permalink
fix files client
Browse files Browse the repository at this point in the history
  • Loading branch information
Tansito committed Dec 26, 2024
1 parent 305775b commit bcf947c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
8 changes: 4 additions & 4 deletions client/qiskit_serverless/core/clients/serverless_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,14 @@ def provider_file_delete(self, file: str, function: QiskitFunction, provider: st
return self._files_client.provider_delete(file, function, provider)

def file_upload(
self, file: str, function: QiskitFunction, provider: Optional[str] = None
self, file: str, function: QiskitFunction
):
"""Upload file."""
return self._files_client.upload(file, function, provider)
return self._files_client.upload(file, function)

def provider_file_upload(self, file: str, function: QiskitFunction, provider: str):
def provider_file_upload(self, file: str, function: QiskitFunction):
"""Upload file."""
return self._files_client.provider_upload(file, function, provider)
return self._files_client.provider_upload(file, function)


class IBMServerlessClient(ServerlessClient):
Expand Down
26 changes: 16 additions & 10 deletions client/qiskit_serverless/core/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ def provider_download(

@_trace
def upload(
self, file: str, function: QiskitFunction, provider: Optional[str] = None
self, file: str, function: QiskitFunction
) -> Optional[str]:
"""Uploads file."""
with open(file, "rb") as f:
with requests.post(
os.path.join(self._files_url, "upload/"),
files={"file": f},
params={"provider": provider, "function": function.title},
params={"provider": function.provider, "function": function.title},
stream=True,
headers={"Authorization": f"Bearer {self._token}"},
timeout=REQUESTS_STREAMING_TIMEOUT,
Expand All @@ -152,14 +152,17 @@ def upload(

@_trace
def provider_upload(
self, file: str, function: QiskitFunction, provider: str
self, file: str, function: QiskitFunction
) -> Optional[str]:
if not function.provider:
raise QiskitServerlessException("`function` doesn't have a provider.")

"""Uploads file to provider/function file storage."""
with open(file, "rb") as f:
with requests.post(
os.path.join(self._files_url, "upload/"),
files={"file": f},
params={"provider": provider, "function": function.title},
params={"provider": function.provider, "function": function.title},
stream=True,
headers={"Authorization": f"Bearer {self._token}"},
timeout=REQUESTS_STREAMING_TIMEOUT,
Expand All @@ -175,7 +178,7 @@ def list(self, function: QiskitFunction) -> List[str]:
response_data = safe_json_request_as_dict(
request=lambda: requests.get(
self._files_url,
params={"function": function.title},
params={"function": function.title, "provider": function.provider},
headers={"Authorization": f"Bearer {self._token}"},
timeout=REQUESTS_TIMEOUT,
)
Expand All @@ -191,7 +194,7 @@ def provider_list(self, function: QiskitFunction) -> List[str]:
response_data = safe_json_request_as_dict(
request=lambda: requests.get(
os.path.join(self._files_url, "provider"),
params={"provider": function.provider, "function": function.title},
params={"function": function.title, "provider": function.provider},
headers={"Authorization": f"Bearer {self._token}"},
timeout=REQUESTS_TIMEOUT,
)
Expand All @@ -200,7 +203,7 @@ def provider_list(self, function: QiskitFunction) -> List[str]:

@_trace
def delete(
self, file: str, function: QiskitFunction, provider: Optional[str] = None
self, file: str, function: QiskitFunction
) -> Optional[str]:
"""Deletes file uploaded or produced by the programs,"""
response_data = safe_json_request_as_dict(
Expand All @@ -209,7 +212,7 @@ def delete(
params={
"file": file,
"function": function.title,
"provider": provider,
"provider": function.provider,
},
headers={
"Authorization": f"Bearer {self._token}",
Expand All @@ -222,16 +225,19 @@ def delete(

@_trace
def provider_delete(
self, file: str, function: QiskitFunction, provider: str
self, file: str, function: QiskitFunction
) -> Optional[str]:
if not function.provider:
raise QiskitServerlessException("`function` doesn't have a provider.")

"""Deletes file uploaded or produced by the programs,"""
response_data = safe_json_request_as_dict(
request=lambda: requests.delete(
os.path.join(self._files_url, "provider", "delete"),
params={
"file": file,
"function": function.title,
"provider": provider,
"provider": function.provider,
},
headers={
"Authorization": f"Bearer {self._token}",
Expand Down

0 comments on commit bcf947c

Please sign in to comment.