FileUploadOption#
- class teamworksams.file_option.FileUploadOption(interactive_mode: bool = True, cache: bool = True, save_to_file: str | None = None)[source]#
Bases:
object
Configuration options for file upload operations.
Customizes the behavior of
upload_and_attach_to_events()
andupload_and_attach_to_avatars()
, controlling interactive feedback, caching, and result storage. These options optimize the upload process for attaching files to events or user avatars. See Uploading Files for file upload workflows.- Parameters:
interactive_mode (bool) – If True, prints status messages (e.g., “Uploading 2 files”) and
tqdm
progress bars during execution, ideal for interactive environments like Jupyter notebooks. Set to False for silent execution. Defaults to True.cache (bool) – If True, reuses cached API responses via the
AMSClient
, reducing API calls for user/event data retrieval or uploads. Set to False for fresh data. Defaults to True.save_to_file (Optional[str]) – File path to save upload results as a CSV (e.g., ‘results.csv’). The CSV includes columns like
user_key
,file_name
,status
, andreason
. If None, results are not saved. Defaults to None.interactive_mode – Whether to print status messages during execution, such as the list of files being uploaded and their file IDs. Defaults to True.
cache – Whether to cache API responses to improve performance for repeated requests. Defaults to True.
save_to_file – The file path to save upload results as a CSV, including file names, file IDs, and server-assigned names. If None, results are not saved to a file. Defaults to None.
- interactive_mode#
Indicates whether interactive mode is enabled.
- Type:
bool
- cache#
Indicates whether caching is enabled.
- Type:
bool
- save_to_file#
The file path for saving results, if specified.
- Type:
Optional[str]
Examples
>>> from teamworksams import FileUploadOption, upload_and_attach_to_events >>> import pandas as pd >>> mapping_df = pd.DataFrame({ ... "username": ["user1"], ... "file_name": ["doc1.pdf"], ... "attachment_id": ["ATT123"] ... }) >>> option = FileUploadOption(interactive_mode = True, save_to_file = "results.csv") >>> results = upload_and_attach_to_events( ... mapping_df = mapping_df, ... file_dir = "/path/to/files", ... user_key = "username", ... form = "Document Store", ... file_field_name = "attachment", ... url = "https://example.smartabase.com/site", ... option = option ... ) ℹ Uploading 1 files... ✔ Successfully attached 1 files to 1 events. ℹ Saved results to 'results.csv'
Additional Notes#
Enable
interactive_mode=True
for detailed progress updates andtqdm
progress bars, crucial for monitoring large file uploads.Use
save_to_file
to store results in a CSV (e.g., ‘results.csv’) for auditing successes and failures, especially when attaching files to events.Set
cache=True
to optimize performance by reusing user and event data during the upload process.
See Also#
upload_and_attach_to_events(): Function for event file uploads.
upload_and_attach_to_avatars(): Function for avatar uploads.
Uploading Files: File upload workflows.