Skip to content

Commit bc4413a

Browse files
authored
Merge pull request #66 from opengisch/check_for_forbidden_characters
Adding validator for files to upload on SDK
2 parents 2d6c74f + ff0538a commit bc4413a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

qfieldcloud_sdk/sdk.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from .interfaces import QfcException, QfcRequest, QfcRequestException
1616
from .utils import calc_etag, log
17+
from pathvalidate import is_valid_filepath
18+
1719

1820
logger = logging.getLogger(__file__)
1921

@@ -493,9 +495,15 @@ def upload_file(
493495
show_progress: Whether to display a progress bar during upload.
494496
job_id: The job ID, required if `upload_type` is PACKAGE. Defaults to an empty string.
495497
498+
Raises:
499+
pathvalidate.ValidationError: Raised when the uploaded file does not have a valid filename.
500+
496501
Returns:
497502
The response object from the upload request.
498503
"""
504+
# if the filepath is invalid, it will throw a new error `pathvalidate.ValidationError`
505+
is_valid_filepath(str(local_filename))
506+
499507
with open(local_filename, "rb") as local_file:
500508
upload_file = local_file
501509
if show_progress:

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ idna>=3.4
55
requests>=2.31.0
66
tqdm>=4.65.0
77
urllib3>=2.0.7
8+
pathvalidate>=3.2.1

0 commit comments

Comments
 (0)