Upload Handling: Tracking and Managing Uploads
This section explains how to track the upload progress, resume interrupted uploads, and handle pending uploads using the Spyne SDK. These functionalities are useful when your app is dealing with media uploads after a shoot is completed.
1. Checking Upload Progress
You can track the progress of uploads by using the uploadProgress() method. This allows you to check how far along an upload is for one or more media files.
val mediaIds = listOf("mediaId1", "mediaId2")
SpyneAutomobileSDK.uploadProgress(mediaIds) { progress ->
// Track the progress here
Log.d(TAG, "Upload progress: $progress%")
}
Parameters:
- mediaIds: A list of media IDs for which you want to track the upload progress.
Response: The method will return a JSON object with the upload progress percentage for each media ID.
Example response:
[
{"mediaId": "68931c3c5c89ea1ed78a9083", "progress": 45},
{"mediaId": "b2f1c3b7d58dfd9a38b7bc4b", "progress": 100}
]
2. Check Pending Uploads
To get information about all the uploads that are pending, use the allPendingUploadShoots() method. This helps you track which media needs to be uploaded.
val pendingUploads = SpyneAutomobileSDK.allPendingUploadShoots()
for (upload in pendingUploads) {
Log.d(TAG, "Pending uploads - ${pendingUploads}")
}
This method returns a JSON array with details of all pending uploads, including:
- dealerVinId: The ID of the inventory record.
- mediaId: The ID of the media being uploaded.
- progress: The current progress of the upload (0% to 100%).
Example response:
[
{shootName:"4JGDA5HB4EA327578","dealerVinId": "786fdebd-8d67-4b83-a612-31fd92cc1aa9", "mediaId": "6895cfaa07c53d3ef2cd5d9e", "progress": 50},
{shootName:"1ZVBP8AM7D5281028","dealerVinId": "a948f7bd-3d27-4fb7-bc4b-d5a5eeb1e11a", "mediaId": "c3bc8b39f8f0e03b4a28ec2b", "progress": 0}
]
3. Resuming Interrupted Uploads
If an upload is interrupted (e.g., due to network issues or app termination), you can resume the upload using the uploadPendingShoots() method.
SpyneAutomobileSDK.uploadPendingShoots(context)
How It Works:
- This method will resume all pending uploads that were interrupted or pending when the app was terminated or put in the background.
- It should ideally be called on the app’s home screen or main landing screen to ensure any incomplete uploads continue in the background.
4. Best Practices
- Resume Interrupted Uploads: Always call uploadPendingShoots(context) when the app is reopened to ensure that any incomplete uploads are resumed.
- Check Pending Uploads: Use allPendingUploadShoots() to verify if any uploads are pending when the app starts, ensuring that no uploads are missed.
- Track Progress: Use uploadProgress() to show upload progress to users, especially for captured shoots.
Updated 8 days ago