Skip to content

Commit b0c1b74

Browse files
authored
Merge pull request #340 from ynput/bugfix/custom-file-id
Upload file: Fix custom file id and activity id
2 parents eeb9508 + f6d31de commit b0c1b74

2 files changed

Lines changed: 62 additions & 54 deletions

File tree

ayon_api/_api.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,12 +1202,12 @@ def upload_project_file(
12021202
project_name: str,
12031203
filepath: str,
12041204
*,
1205-
content_type: Optional[str] = None,
1206-
filename: Optional[str] = None,
1207-
file_id: Optional[str] = None,
1208-
activity_id: Optional[str] = None,
1209-
chunk_size: Optional[int] = None,
1210-
progress: Optional[TransferProgress] = None,
1205+
content_type: str | None = None,
1206+
filename: str | None = None,
1207+
file_id: str | None = None,
1208+
activity_id: str | None = None,
1209+
chunk_size: int | None = None,
1210+
progress: TransferProgress | None = None,
12111211
) -> requests.Response:
12121212
"""Upload project file from a filepath.
12131213
@@ -1218,14 +1218,14 @@ def upload_project_file(
12181218
Args:
12191219
project_name (str): Project name.
12201220
filepath (str): Path where file will be downloaded.
1221-
content_type (Optional[str]): MIME type of file.
1222-
filename (Optional[str]): Server filename, filename from filepath
1221+
content_type (str | None): MIME type of file.
1222+
filename (str | None): Server filename, filename from filepath
12231223
is used if not passed.
1224-
file_id (Optional[str]): File id.
1225-
activity_id (Optional[str]): To which activity is file related.
1226-
chunk_size (Optional[int]): Size of chunks that are received
1224+
file_id (str | None): File id.
1225+
activity_id (str | None): To which activity is file related.
1226+
chunk_size (int | None): Size of chunks that are received
12271227
in single loop.
1228-
progress (Optional[TransferProgress]): Object that gives ability
1228+
progress (TransferProgress | None): Object that gives ability
12291229
to track download progress.
12301230
12311231
Returns:
@@ -1250,11 +1250,11 @@ def upload_project_file_from_stream(
12501250
stream: StreamType,
12511251
filename: str,
12521252
*,
1253-
content_type: Optional[str] = None,
1254-
file_id: Optional[str] = None,
1255-
activity_id: Optional[str] = None,
1256-
chunk_size: Optional[int] = None,
1257-
progress: Optional[TransferProgress] = None,
1253+
content_type: str | None = None,
1254+
file_id: str | None = None,
1255+
activity_id: str | None = None,
1256+
chunk_size: int | None = None,
1257+
progress: TransferProgress | None = None,
12581258
) -> requests.Response:
12591259
"""Upload project file from a filepath.
12601260
@@ -1266,12 +1266,12 @@ def upload_project_file_from_stream(
12661266
project_name (str): Project name.
12671267
stream (StreamType): Stream used as source for upload.
12681268
filename (str): Name of file on server.
1269-
content_type (Optional[str]): MIME type of file.
1270-
file_id (Optional[str]): File id.
1271-
activity_id (Optional[str]): To which activity is file related.
1272-
chunk_size (Optional[int]): Size of chunks that are received
1269+
content_type (str | None): MIME type of file.
1270+
file_id (str | None): File id.
1271+
activity_id (str | None): To which activity is file related.
1272+
chunk_size (int | None): Size of chunks that are received
12731273
in single loop.
1274-
progress (Optional[TransferProgress]): Object that gives ability
1274+
progress (TransferProgress | None): Object that gives ability
12751275
to track download progress.
12761276
12771277
Returns:

ayon_api/server_api.py

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,12 +1806,12 @@ def upload_project_file(
18061806
project_name: str,
18071807
filepath: str,
18081808
*,
1809-
content_type: Optional[str] = None,
1810-
filename: Optional[str] = None,
1811-
file_id: Optional[str] = None,
1812-
activity_id: Optional[str] = None,
1813-
chunk_size: Optional[int] = None,
1814-
progress: Optional[TransferProgress] = None,
1809+
content_type: str | None = None,
1810+
filename: str | None = None,
1811+
file_id: str | None = None,
1812+
activity_id: str | None = None,
1813+
chunk_size: int | None = None,
1814+
progress: TransferProgress | None = None,
18151815
) -> requests.Response:
18161816
"""Upload project file from a filepath.
18171817
@@ -1822,14 +1822,14 @@ def upload_project_file(
18221822
Args:
18231823
project_name (str): Project name.
18241824
filepath (str): Path where file will be downloaded.
1825-
content_type (Optional[str]): MIME type of file.
1826-
filename (Optional[str]): Server filename, filename from filepath
1825+
content_type (str | None): MIME type of file.
1826+
filename (str | None): Server filename, filename from filepath
18271827
is used if not passed.
1828-
file_id (Optional[str]): File id.
1829-
activity_id (Optional[str]): To which activity is file related.
1830-
chunk_size (Optional[int]): Size of chunks that are received
1828+
file_id (str | None): File id.
1829+
activity_id (str | None): To which activity is file related.
1830+
chunk_size (int | None): Size of chunks that are received
18311831
in single loop.
1832-
progress (Optional[TransferProgress]): Object that gives ability
1832+
progress (TransferProgress | None): Object that gives ability
18331833
to track download progress.
18341834
18351835
Returns:
@@ -1844,17 +1844,21 @@ def upload_project_file(
18441844
if not content_type:
18451845
content_type = "application/octet-stream"
18461846

1847-
query = prepare_query_string({
1848-
"x_file_id": file_id,
1849-
"x_activity_id": activity_id,
1850-
})
1847+
headers = {}
1848+
if file_id:
1849+
headers["x-file-id"] = file_id
1850+
1851+
if activity_id:
1852+
headers["x-activity-id"] = activity_id
1853+
18511854
return self.upload_file(
1852-
f"api/projects/{project_name}/files{query}",
1855+
f"api/projects/{project_name}/files",
18531856
filepath,
18541857
content_type=content_type,
18551858
filename=filename,
18561859
chunk_size=chunk_size,
18571860
progress=progress,
1861+
headers=headers,
18581862
request_type=RequestTypes.post,
18591863
)
18601864

@@ -1864,11 +1868,11 @@ def upload_project_file_from_stream(
18641868
stream: StreamType,
18651869
filename: str,
18661870
*,
1867-
content_type: Optional[str] = None,
1868-
file_id: Optional[str] = None,
1869-
activity_id: Optional[str] = None,
1870-
chunk_size: Optional[int] = None,
1871-
progress: Optional[TransferProgress] = None,
1871+
content_type: str | None = None,
1872+
file_id: str | None = None,
1873+
activity_id: str | None = None,
1874+
chunk_size: int | None = None,
1875+
progress: TransferProgress | None = None,
18721876
) -> requests.Response:
18731877
"""Upload project file from a filepath.
18741878
@@ -1880,12 +1884,12 @@ def upload_project_file_from_stream(
18801884
project_name (str): Project name.
18811885
stream (StreamType): Stream used as source for upload.
18821886
filename (str): Name of file on server.
1883-
content_type (Optional[str]): MIME type of file.
1884-
file_id (Optional[str]): File id.
1885-
activity_id (Optional[str]): To which activity is file related.
1886-
chunk_size (Optional[int]): Size of chunks that are received
1887+
content_type (str | None): MIME type of file.
1888+
file_id (str | None): File id.
1889+
activity_id (str | None): To which activity is file related.
1890+
chunk_size (int | None): Size of chunks that are received
18871891
in single loop.
1888-
progress (Optional[TransferProgress]): Object that gives ability
1892+
progress (TransferProgress | None): Object that gives ability
18891893
to track download progress.
18901894
18911895
Returns:
@@ -1898,17 +1902,21 @@ def upload_project_file_from_stream(
18981902
if not content_type:
18991903
content_type = "application/octet-stream"
19001904

1901-
query = prepare_query_string({
1902-
"x_file_id": file_id,
1903-
"x_activity_id": activity_id,
1904-
})
1905+
headers = {}
1906+
if file_id:
1907+
headers["x-file-id"] = file_id
1908+
1909+
if activity_id:
1910+
headers["x-activity-id"] = activity_id
1911+
19051912
return self.upload_file_from_stream(
1906-
f"api/projects/{project_name}/files{query}",
1913+
f"api/projects/{project_name}/files",
19071914
stream,
19081915
content_type=content_type,
19091916
filename=filename,
19101917
chunk_size=chunk_size,
19111918
progress=progress,
1919+
headers=headers,
19121920
request_type=RequestTypes.post,
19131921
)
19141922

0 commit comments

Comments
 (0)