Not to put/send jpg files if that is already sent to server (exit in server)

Discussions about syncing data via Bluetooth, Dropbox, FTP, and using CSWeb
Forum rules
New release: CSPro 8.0
Post Reply
pradhanra01
Posts: 38
Joined: August 27th, 2017, 2:43 am

Not to put/send jpg files if that is already sent to server (exit in server)

Post by pradhanra01 »

Hi Sherrell,

I have a project collecting data with taking each respondent/outlet's photograph. I have handeled the naming of photograph with the using serial key of respondent ID.

I have used below syntax to upload/send photo to server..

SyncFile(PUT,"*.jpg",concat(ProjName,"/Photos/","/")); // photo file copy to server

Now my concern is while user uploads photo 2nd time onward, it should ignore the files which have been already uploaded in server before or if file already exist in server (specific folder). I was thinking for saving time and internet bandwidth for uploading jpg files in server.

Could you please suggest how can I check if files are already exists in server for not to copy in uploading time.

With Regards,
Ramesh Pradhan
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: Not to put/send jpg files if that is already sent to server (exit in server)

Post by htuser »

Now my concern is while user uploads photo 2nd time onward, it should ignore the files which have been already uploaded in server before or if file already exist in server (specific folder). I was thinking for saving time and internet bandwidth for uploading jpg files in server.
Years ago, Aaron and Josh helped me about similar topics. Normally there's several solutions, among others:

a) Hash (unique signature) of the file.It's widely used for such things; If a specific file exist on both folders : server and local and have the same hash, do not download/upload;
b) However, because in CSPro there's no way to have the hash of file. The existing CSPro built-in diagnostics(ʃpropertyʅʃ, argument, ...ʅ) function allow only having a MD5 hash of a CSPro app... So, Aaron advised me to rename files once I successfully put them to the server. Here's a sample code I used 4-5 years ago (inside a user defined function) for this purpose:
    if syncconnect(CSWeb,ServerUrl_Internet,"admin",password_internet)= 1 then
string
imageFileDirectory=maketext (pathname(Application) + "Applications\AppName"+"\Data\Images");
   
        dirlist(imageFileListing,imageFileDirectory,"*.jpg");
        //Errmsg  ("La liste des fichiers est %v",imageFileListing);
       
do numeric i = 1 while i <= length(imageFileListing)
            string imageFileName =imageFileListing(i);
            //Errmsg  ("Le fichier qui sera synchronise est %v",imageFileName);
           
if (syncfile(PUT,imageFileName,"\Images\"))=1
               
then
               
//Errmsg  ("Le fichier qui ete synchronise est %v",imageFileName);
               
if (filerename(imageFileName,imageFileName + ".JPG"))=1
                   
then
                   
//Errmsg  ("Le fichier qui ete renome est %v",imageFileName);
               
endif;
            endif;
        enddo;
    else
        Errmsg 
("La connexion n'est pas ouverte");
    endif;
I think that right now because of the JS-CSPro API it's possible to use JS libs able to calculate Hash for any file and use the a) who's a better approach.
Hope this help you!
G.VOLNY, a CSProuser from Haiti, since 2004
Post Reply