Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Automatically upload data on server from selected directory path

Automatically upload data on server from selected directory path

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 4 Posters 4.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    developerNancy
    wrote on 8 May 2017, 12:01 last edited by developerNancy 5 Aug 2017, 12:02
    #1

    I have developed linux app to upload data on server from selected folder on button click and saving that data in sent folder Now I want to upload data automatically when there is any files in folder.

    If any one knows how to upload data automatically if user select an directory only one time then please let me know?

    K 1 Reply Last reply 8 May 2017, 13:00
    0
    • D developerNancy
      8 May 2017, 12:01

      I have developed linux app to upload data on server from selected folder on button click and saving that data in sent folder Now I want to upload data automatically when there is any files in folder.

      If any one knows how to upload data automatically if user select an directory only one time then please let me know?

      K Offline
      K Offline
      koahnig
      wrote on 8 May 2017, 13:00 last edited by
      #2

      @developerNancy

      You can find out if there are files in a folder with QDir::entryInfoList with filter QDir::Files

      Vote the answer(s) that helped you to solve your issue(s)

      D 1 Reply Last reply 8 May 2017, 13:02
      0
      • K koahnig
        8 May 2017, 13:00

        @developerNancy

        You can find out if there are files in a folder with QDir::entryInfoList with filter QDir::Files

        D Offline
        D Offline
        developerNancy
        wrote on 8 May 2017, 13:02 last edited by
        #3

        @koahnig I have done with uploading on button click but Now I want to upload automatically when new file added in that folder.

        J K 2 Replies Last reply 8 May 2017, 13:14
        0
        • D developerNancy
          8 May 2017, 13:02

          @koahnig I have done with uploading on button click but Now I want to upload automatically when new file added in that folder.

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 8 May 2017, 13:14 last edited by
          #4

          @developerNancy Than you'll have to save a reference of the QDir::entryInfoList in a member variable and periotically call QDir::entryInfoList to compare with your member variable List.

          If the latest call contains a file not in your m-Varibale, update your list and upload the new file.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          D 1 Reply Last reply 9 May 2017, 05:51
          0
          • D developerNancy
            8 May 2017, 13:02

            @koahnig I have done with uploading on button click but Now I want to upload automatically when new file added in that folder.

            K Offline
            K Offline
            koahnig
            wrote on 8 May 2017, 14:34 last edited by
            #5

            @developerNancy

            There is also the QFileSystemWatcher which tells you when there is a change.

            Vote the answer(s) that helped you to solve your issue(s)

            D 1 Reply Last reply 9 May 2017, 05:18
            3
            • K koahnig
              8 May 2017, 14:34

              @developerNancy

              There is also the QFileSystemWatcher which tells you when there is a change.

              D Offline
              D Offline
              developerNancy
              wrote on 9 May 2017, 05:18 last edited by
              #6

              @koahnig I have done with that My main query is to upload automatically

              1 Reply Last reply
              0
              • J J.Hilk
                8 May 2017, 13:14

                @developerNancy Than you'll have to save a reference of the QDir::entryInfoList in a member variable and periotically call QDir::entryInfoList to compare with your member variable List.

                If the latest call contains a file not in your m-Varibale, update your list and upload the new file.

                D Offline
                D Offline
                developerNancy
                wrote on 9 May 2017, 05:51 last edited by
                #7

                @J.Hilk After getting new file How to send it to server automatically?

                K J J 3 Replies Last reply 9 May 2017, 06:11
                0
                • D developerNancy
                  9 May 2017, 05:51

                  @J.Hilk After getting new file How to send it to server automatically?

                  K Offline
                  K Offline
                  koahnig
                  wrote on 9 May 2017, 06:11 last edited by
                  #8

                  @developerNancy said in Automatically upload data on server from selected directory path:

                  @J.Hilk After getting new file How to send it to server automatically?

                  @koahnig said in Automatically upload data on server from selected directory path:

                  @developerNancy

                  There is also the QFileSystemWatcher which tells you when there is a change.

                  Follow the link given in the post above.

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  0
                  • D developerNancy
                    9 May 2017, 05:51

                    @J.Hilk After getting new file How to send it to server automatically?

                    J Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 9 May 2017, 06:20 last edited by J.Hilk 5 Sept 2017, 12:53
                    #9

                    @developerNancy

                    I didn't knwo QFileSystemWatcher was a thing so I'll use that.

                    //*.h
                    #include <QFileSystemWatcher>
                    ...
                    
                    private slots:
                       void uploadViaQNetworkManager(QString filePath){//Your upload code;}
                    
                       void watcherSlot(QString s);
                    
                    private:
                        QFileSystemWatcher watcher; 
                        QList<QString> m_refList;
                    
                    //*.cpp
                    watcher.addPath(PathToUploadFolder);
                    QDir dir; 
                    dir.setPath(PathToUploadFolder);
                    if(!dir.entryList(QDir::Files).isEmpty())
                            for(auto &str :dir.entryList(QDir::Files | QDir::NoDotAndDotDot)){
                                m_refList.append( str);
                    
                    connect(&watcher, &QFileSystemWatcher::directoryChanged, this, &myClass::watcherSlot);
                    
                    void myClass::watcherSlot(QString s){
                       QString newfile;
                       QDir dir; 
                       dir.setPath(s);
                       if(!dir.entryList(QDir::Files).isEmpty())
                           for(int i = 0; i < m_refList.size(); i++){
                               bool newEntry = true;;
                               for(newfile : dir.entryList(QDir::Files | QDir::NoDotAndDotDot)){
                                   if(m_refList.at(i) == newfile)
                                      newEntry = false;
                                if(newEntry){
                                   uploadViaQNetworkManager(s+"\n"+newfile);
                                   m_refList.append(newfile);
                                 }
                            }
                    }
                    

                    Disclaimer this is pseudo code and untested. But the prinziple should be valid

                    Edit: changed the filter from dirs to files.


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    D 1 Reply Last reply 9 May 2017, 16:39
                    0
                    • D developerNancy
                      9 May 2017, 05:51

                      @J.Hilk After getting new file How to send it to server automatically?

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 9 May 2017, 06:23 last edited by
                      #10

                      @developerNancy said in Automatically upload data on server from selected directory path:

                      After getting new file How to send it to server automatically?

                      Didn't you say in your first post that you already implemented uploading to the server?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      D 1 Reply Last reply 9 May 2017, 09:57
                      0
                      • J jsulm
                        9 May 2017, 06:23

                        @developerNancy said in Automatically upload data on server from selected directory path:

                        After getting new file How to send it to server automatically?

                        Didn't you say in your first post that you already implemented uploading to the server?

                        D Offline
                        D Offline
                        developerNancy
                        wrote on 9 May 2017, 09:57 last edited by
                        #11

                        @jsulm Yes I have done with Uploading Multiple files to server Now I want to implement background sync. like if any file copy in selected folder than it automatically uploaded to server. For this watcher or threading which is the best solution.....

                        J 1 Reply Last reply 9 May 2017, 11:01
                        0
                        • D developerNancy
                          9 May 2017, 09:57

                          @jsulm Yes I have done with Uploading Multiple files to server Now I want to implement background sync. like if any file copy in selected folder than it automatically uploaded to server. For this watcher or threading which is the best solution.....

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 9 May 2017, 11:01 last edited by
                          #12

                          @developerNancy That I understand. What I don't understand: if you're able to upload multiple files why can't you upload one? So, what exactly is the problem?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          D 1 Reply Last reply 9 May 2017, 12:34
                          0
                          • J jsulm
                            9 May 2017, 11:01

                            @developerNancy That I understand. What I don't understand: if you're able to upload multiple files why can't you upload one? So, what exactly is the problem?

                            D Offline
                            D Offline
                            developerNancy
                            wrote on 9 May 2017, 12:34 last edited by
                            #13

                            @jsulm I want to sync data in background it automatically uploaded when new file is added in directory no need to click again upload button.

                            J 1 Reply Last reply 9 May 2017, 12:38
                            0
                            • D developerNancy
                              9 May 2017, 12:34

                              @jsulm I want to sync data in background it automatically uploaded when new file is added in directory no need to click again upload button.

                              J Offline
                              J Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 9 May 2017, 12:38 last edited by
                              #14

                              @developerNancy That I understand. You already was pointed to QFileSystemWatcher, @J-Hilk even provided code. So, what is not working?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              D 1 Reply Last reply 9 May 2017, 13:23
                              0
                              • J jsulm
                                9 May 2017, 12:38

                                @developerNancy That I understand. You already was pointed to QFileSystemWatcher, @J-Hilk even provided code. So, what is not working?

                                D Offline
                                D Offline
                                developerNancy
                                wrote on 9 May 2017, 13:23 last edited by
                                #15

                                @jsulm which is the best approach for background sync I am Implementing thread ...

                                1 Reply Last reply
                                0
                                • J J.Hilk
                                  9 May 2017, 06:20

                                  @developerNancy

                                  I didn't knwo QFileSystemWatcher was a thing so I'll use that.

                                  //*.h
                                  #include <QFileSystemWatcher>
                                  ...
                                  
                                  private slots:
                                     void uploadViaQNetworkManager(QString filePath){//Your upload code;}
                                  
                                     void watcherSlot(QString s);
                                  
                                  private:
                                      QFileSystemWatcher watcher; 
                                      QList<QString> m_refList;
                                  
                                  //*.cpp
                                  watcher.addPath(PathToUploadFolder);
                                  QDir dir; 
                                  dir.setPath(PathToUploadFolder);
                                  if(!dir.entryList(QDir::Files).isEmpty())
                                          for(auto &str :dir.entryList(QDir::Files | QDir::NoDotAndDotDot)){
                                              m_refList.append( str);
                                  
                                  connect(&watcher, &QFileSystemWatcher::directoryChanged, this, &myClass::watcherSlot);
                                  
                                  void myClass::watcherSlot(QString s){
                                     QString newfile;
                                     QDir dir; 
                                     dir.setPath(s);
                                     if(!dir.entryList(QDir::Files).isEmpty())
                                         for(int i = 0; i < m_refList.size(); i++){
                                             bool newEntry = true;;
                                             for(newfile : dir.entryList(QDir::Files | QDir::NoDotAndDotDot)){
                                                 if(m_refList.at(i) == newfile)
                                                    newEntry = false;
                                              if(newEntry){
                                                 uploadViaQNetworkManager(s+"\n"+newfile);
                                                 m_refList.append(newfile);
                                               }
                                          }
                                  }
                                  

                                  Disclaimer this is pseudo code and untested. But the prinziple should be valid

                                  Edit: changed the filter from dirs to files.

                                  D Offline
                                  D Offline
                                  developerNancy
                                  wrote on 9 May 2017, 16:39 last edited by
                                  #16

                                  @J.Hilk Can you please explain How I get the Path and watcher active after button click.

                                  J 1 Reply Last reply 9 May 2017, 17:42
                                  0
                                  • D developerNancy
                                    9 May 2017, 16:39

                                    @J.Hilk Can you please explain How I get the Path and watcher active after button click.

                                    J Offline
                                    J Offline
                                    J.Hilk
                                    Moderators
                                    wrote on 9 May 2017, 17:42 last edited by
                                    #17

                                    @developerNancy you don't share any code sample with us, so it's hard to give definite working answers. You'll have to take what we write and integrate into your project.

                                    That said I gave you a rough example how to setup and use the watcher.

                                    @J.Hilk said in Automatically upload data on server from selected directory path:

                                    @developerNancy

                                    //*.h
                                    QFileSystemWatcher watcher;
                                    
                                    //*.cpp
                                    watcher.addPath(PathToUploadFolder);
                                    QDir dir; 
                                    dir.setPath(PathToUploadFolder);
                                    if(!dir.entryList(QDir::Files).isEmpty())
                                            for(auto &str :dir.entryList(QDir::Files | QDir::NoDotAndDotDot)){
                                                m_refList.append( str);
                                    
                                    connect(&watcher, &QFileSystemWatcher::directoryChanged, this, &myClass::watcherSlot);
                                    

                                    @developerNancy said in Automatically upload data on server from selected directory path:

                                    How I get the Path

                                    I don't know! How do you specify the folder for the multi file upload to the server? Just copy that path to a Qstring and give it to your QFileSystemWatcher-Instance


                                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                    Q: What's that?
                                    A: It's blue light.
                                    Q: What does it do?
                                    A: It turns blue.

                                    1 Reply Last reply
                                    0

                                    1/17

                                    8 May 2017, 12:01

                                    • Login

                                    • Login or register to search.
                                    1 out of 17
                                    • First post
                                      1/17
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved