Skip to content

Commit 43d31ad

Browse files
authored
Merge pull request #51 from gdcc/fix-url-build
Improve URL building and display S3 upload mode per file
2 parents 8ea6e03 + a27499d commit 43d31ad

2 files changed

Lines changed: 32 additions & 17 deletions

File tree

dvuploader/directupload.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from rich.progress import Progress, TaskID
1111

1212
from dvuploader.file import File
13-
from dvuploader.utils import build_url, init_logging, wait_for_dataset_unlock
13+
from dvuploader.utils import init_logging, wait_for_dataset_unlock
1414

1515
TESTING = bool(os.environ.get("DVUPLOADER_TESTING", False))
1616
MAX_FILE_DISPLAY = int(os.environ.get("DVUPLOADER_MAX_FILE_DISPLAY", 50))
@@ -69,6 +69,7 @@ async def direct_upload(
6969
"timeout": None,
7070
"limits": httpx.Limits(max_connections=n_parallel_uploads),
7171
"proxy": proxy,
72+
"base_url": dataverse_url,
7273
}
7374

7475
async with httpx.AsyncClient(**session_params) as session:
@@ -106,6 +107,7 @@ async def direct_upload(
106107
"timeout": None,
107108
"limits": httpx.Limits(max_connections=n_parallel_uploads),
108109
"headers": headers,
110+
"base_url": dataverse_url,
109111
}
110112

111113
async with httpx.AsyncClient(**session_params) as session:
@@ -159,6 +161,10 @@ async def _upload_to_store(
159161
)
160162

161163
if "urls" not in ticket:
164+
# Update the progress bar description and append [Singlepart]
165+
progress.update(
166+
pbar, description=f"Uploading file '{file.file_name}' [Singlepart]"
167+
)
162168
status, storage_identifier = await _upload_singlepart(
163169
session=session,
164170
ticket=ticket,
@@ -170,6 +176,10 @@ async def _upload_to_store(
170176
)
171177

172178
else:
179+
# Update the progress bar description and append [Multipart]
180+
progress.update(
181+
pbar, description=f"Uploading file '{file.file_name}' [Multipart]"
182+
)
173183
status, storage_identifier = await _upload_multipart(
174184
session=session,
175185
response=ticket,
@@ -205,14 +215,17 @@ async def _request_ticket(
205215
Returns:
206216
Dict: Upload ticket containing URL and storage identifier.
207217
"""
208-
url = build_url(
209-
endpoint=urljoin(dataverse_url, TICKET_ENDPOINT),
210-
key=api_token,
211-
persistentId=persistent_id,
212-
size=file_size,
218+
response = await session.get(
219+
TICKET_ENDPOINT,
220+
timeout=None,
221+
params={
222+
"size": file_size,
223+
"persistentId": persistent_id,
224+
},
225+
headers={
226+
"X-Dataverse-key": api_token,
227+
},
213228
)
214-
215-
response = await session.get(url, timeout=None)
216229
response.raise_for_status()
217230

218231
return response.json()["data"]

dvuploader/dvuploader.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818
from dvuploader.file import File
1919
from dvuploader.nativeupload import native_upload
20-
from dvuploader.utils import build_url, retrieve_dataset_files, setup_pbar
20+
from dvuploader.utils import retrieve_dataset_files, setup_pbar
2121

2222

2323
class DVUploader(BaseModel):
@@ -410,15 +410,17 @@ def _has_direct_upload(
410410
bool: True if direct upload is supported, False otherwise.
411411
"""
412412

413-
query = build_url(
414-
endpoint=urljoin(dataverse_url, TICKET_ENDPOINT),
415-
key=api_token,
416-
persistentId=persistent_id,
417-
size=1024,
418-
)
419-
420413
# Send HTTP request
421-
response = httpx.get(query)
414+
response = httpx.get(
415+
urljoin(dataverse_url, TICKET_ENDPOINT),
416+
params={
417+
"size": 1024,
418+
"persistentId": persistent_id,
419+
},
420+
headers={
421+
"X-Dataverse-key": api_token,
422+
},
423+
)
422424

423425
if response.status_code == 404:
424426
return False

0 commit comments

Comments
 (0)