fix(connection): support absolute download urls for public data

This commit is contained in:
2026-06-11 21:04:28 +09:00
parent 428be1289c
commit 04c0003a61
4 changed files with 13 additions and 9 deletions
+1 -6
View File
@@ -5,12 +5,7 @@ from pydantic import TypeAdapter
from requests import Response
from mdrsclient.connection import MDRSConnection
from mdrsclient.exceptions import (
BadRequestException,
ForbiddenException,
UnauthorizedException,
UnexpectedException,
)
from mdrsclient.exceptions import BadRequestException, ForbiddenException, UnauthorizedException, UnexpectedException
from mdrsclient.models.error import DRFStandardizedErrors
+7 -2
View File
@@ -54,7 +54,10 @@ class FilesApi(BaseApi):
try:
with open(os.path.realpath(path), mode="rb") as fp:
data = MultipartEncoder(
fields={"folder_id": folder_id, "file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path))}
fields={
"folder_id": folder_id,
"file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path)),
}
)
response = self.connection.post(url, data=data, headers={"Content-Type": data.content_type})
self._raise_response_error(response)
@@ -76,7 +79,9 @@ class FilesApi(BaseApi):
# update file body
try:
with open(os.path.realpath(path), mode="rb") as fp:
data = MultipartEncoder(fields={"file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path))})
data = MultipartEncoder(
fields={"file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path))}
)
response = self.connection.put(url, data=data, headers={"Content-Type": data.content_type})
except OSError:
raise UnexpectedException(f"Could not open `{path}` file.")