Can a photo be synchronised?
Can a photo be synchronised?
Please colleagues,
Is it possible to synchronize a picture file between a client and server?
If yes, how do I go about this? I also mean to say, is there a logic that must be written to support this process?
Is it possible to synchronize a picture file between a client and server?
If yes, how do I go about this? I also mean to say, is there a logic that must be written to support this process?
Re: Can a photo be synchronised?
Synchronization works with any kind of file including photos. To upload the photo from client to server you simply need to add a line in the .pnc file like:
Put myphoto.jpg
but replace myphoto.jpg with the name of the photo file. If the photo file is not in the CSEntry directory you will need to use SetClientPath to switch to the directory that the photo file is in. You may also want to use SetServerPath to control which directory the file is sent to on the server. For details on the .pnc file see the Android data transfer guide: https://www.census.gov/population/inter ... 20Help.pdf
Put myphoto.jpg
but replace myphoto.jpg with the name of the photo file. If the photo file is not in the CSEntry directory you will need to use SetClientPath to switch to the directory that the photo file is in. You may also want to use SetServerPath to control which directory the file is sent to on the server. For details on the .pnc file see the Android data transfer guide: https://www.census.gov/population/inter ... 20Help.pdf
Re: Can a photo be synchronised?
Hi, The issue comes when you want to sync the pic associated with the case, suppose you are taking a pic for every case but you want to sync one by one though the dat files will be incremental.
How do you go about it?
How do you go about it?
Re: Can a photo be synchronised?
If you want to only sync the photos that have not already been synced it is a bit tricky. You would have to use sync from logic i.e. call the sync() function from your program logic. When you take the photos you could put them in a directory named "tosync". Then when you sync you use put to send all the photos in the "tosync" directory to the server. If the call to sync() succeeds then you copy all the photos from "tosync" to another directory "synced" and delete them from the "tosync" directory.
-
- Posts: 6
- Joined: May 31st, 2017, 4:53 am
Re: Can a photo be synchronised?
Hi Josh, sorry for reviving a really old post. I've coded my application in the way you describe. Photos are initially stored in the "photos" folder and when they're uploaded they're moved to the "Uploaded folder" like so:josh wrote:If you want to only sync the photos that have not already been synced it is a bit tricky. You would have to use sync from logic i.e. call the sync() function from your program logic. When you take the photos you could put them in a directory named "tosync". Then when you sync you use put to send all the photos in the "tosync" directory to the server. If the call to sync() succeeds then you copy all the photos from "tosync" to another directory "synced" and delete them from the "tosync" directory.
Code: Select all
// send the latest photos
if syncfile(PUT,"./photos/*", "/InspectionPhotos/") then
msg = "Collected Data and Photos Uploaded";
endif;
if filecopy(pathname(Application) + "./photos/*", "Uploaded") <> default then
filedelete(pathname(Application) + "./photos/*");
endif;
Re: Can a photo be synchronised?
Move the filecopy/filedelete inside the if statement so that it only gets called if the sync is successful. That way if the user cancels part way through it will not move the file. It will try to sync the file again next time they user syncs.
For running out of disk space I don't have a solution other than to free up space on the device. You could just delete the synced photos instead of copying them to "uploaded" although I would first look for other things taking up on the devices like video and audio files.
For running out of disk space I don't have a solution other than to free up space on the device. You could just delete the synced photos instead of copying them to "uploaded" although I would first look for other things taking up on the devices like video and audio files.
-
- Posts: 6
- Joined: May 31st, 2017, 4:53 am
Re: Can a photo be synchronised?
I did as you suggested but one problem I've encountered is when there are hundreds of photos to sync. For example, let's say there are 100 photos to sync and the user syncs 99 photos before hitting cancel. The next time it tries to sync from the first photo again. Is there a way to loop through the available photos and sync/move them one at a time? That way I could have much more granular control over what's been synced and what hasn't.josh wrote:Move the filecopy/filedelete inside the if statement so that it only gets called if the sync is successful. That way if the user cancels part way through it will not move the file. It will try to sync the file again next time they user syncs.
Something like this:
Code: Select all
for photo in photos:
if sync(photo):
move(photo)
else:
show an error
Sometimes even when there's enough disk space it's truncating files to zero bytes during the copy operation. This has led to some loss of data. I was thinking instead of copying/moving to just rename the current folder with a timestamp and create a new folder for new pictures. Is there an easy way to rename a folder because I can't find it in the functions.josh wrote:For running out of disk space I don't have a solution other than to free up space on the device. You could just delete the synced photos instead of copying them to "uploaded" although I would first look for other things taking up on the devices like video and audio files.
Here's the idea:
1. User tries to sync a folder called photos
2. After all the files from photos are uploaded, we rename the photos folder to uploaded-timestamp
3. And we create a new empty folder called photos
This way we avoid the filedelete() command and space issues won't matter. What do you think?
Re: Can a photo be synchronised?
You could use the dirlist function to list the photos directory and then loop through the listing and make individual calls to syncfile followed by filecopy/filedete for each individual photo.
I'm surprised that filecopy is truncating the files. If you can reproduce that behavior please let us know how so we can fix it if there is a problem. Are you checking the return value of filecopy to see if it returns an error? It should return the number of files copied if it works or default if it fails.
Have you tried using filerename (http://www.csprousers.org/help/CSPro/fi ... ction.html) on the folder? I think it should would although I haven't actually tested it.
I'm surprised that filecopy is truncating the files. If you can reproduce that behavior please let us know how so we can fix it if there is a problem. Are you checking the return value of filecopy to see if it returns an error? It should return the number of files copied if it works or default if it fails.
Have you tried using filerename (http://www.csprousers.org/help/CSPro/fi ... ction.html) on the folder? I think it should would although I haven't actually tested it.
-
- Posts: 6
- Joined: May 31st, 2017, 4:53 am
Re: Can a photo be synchronised?
So far I've only had it happen on Android devices (CSEntry) and not on the desktop version. This is the code I'm running:josh wrote:I'm surprised that filecopy is truncating the files. If you can reproduce that behavior please let us know how so we can fix it if there is a problem. Are you checking the return value of filecopy to see if it returns an error? It should return the number of files copied if it works or default if it fails.
Code: Select all
if filecopy(pathname(Application) + "./photos/*", "Uploaded") <> default then
filedelete(pathname(Application) + "./photos/*");
endif;
Heeding your advice, I have since updated my code to the following:
Code: Select all
dirlist(insp_photos,"photos","*",recursive);
do ctr = 1 while ctr <= length(insp_photos)
msg = "Collected Data+Photos Uploaded and Application Updated!";
if syncfile(PUT,insp_photos(ctr),"/InspectionPhotos/") then
if filecopy(insp_photos(ctr), "Uploaded") <> default then
filedelete(insp_photos(ctr));
endif;
else
msg = "Collected Data+Photos Uploaded and Application Updated! Photo upload has been cancelled or failed!";
break;
endif;
enddo;