How can I upload file (images) one by one in a sequential manner in the background in Ionic 3?









up vote
0
down vote

favorite












I read this blog and found out about the file Transfer plugin. They used it to send a file(image) to the server. I want to send multiple file to a server one by one in a sequential order.






public uploadImage() 
// Destination URL
var url = "http://yoururl/upload.php";

// File for Upload
var targetPath = this.pathForImage(this.lastImage);

// File name only
var filename = this.lastImage;

var options =
fileKey: "file",
fileName: filename,
chunkedMode: false,
mimeType: "multipart/form-data",
params : 'fileName': filename
;

const fileTransfer: TransferObject = this.transfer.create();

this.loading = this.loadingCtrl.create(
content: 'Uploading...',
);
this.loading.present();

// Use the FileTransfer to upload the image
fileTransfer.upload(targetPath, url, options).then(data =>
this.loading.dismissAll()
this.presentToast('Image succesful uploaded.');
, err =>
this.loading.dismissAll()
this.presentToast('Error while uploading file.');
);





How can I call this code in a sequential manner, so that when one transfer finishes, another starts?










share|improve this question

























    up vote
    0
    down vote

    favorite












    I read this blog and found out about the file Transfer plugin. They used it to send a file(image) to the server. I want to send multiple file to a server one by one in a sequential order.






    public uploadImage() 
    // Destination URL
    var url = "http://yoururl/upload.php";

    // File for Upload
    var targetPath = this.pathForImage(this.lastImage);

    // File name only
    var filename = this.lastImage;

    var options =
    fileKey: "file",
    fileName: filename,
    chunkedMode: false,
    mimeType: "multipart/form-data",
    params : 'fileName': filename
    ;

    const fileTransfer: TransferObject = this.transfer.create();

    this.loading = this.loadingCtrl.create(
    content: 'Uploading...',
    );
    this.loading.present();

    // Use the FileTransfer to upload the image
    fileTransfer.upload(targetPath, url, options).then(data =>
    this.loading.dismissAll()
    this.presentToast('Image succesful uploaded.');
    , err =>
    this.loading.dismissAll()
    this.presentToast('Error while uploading file.');
    );





    How can I call this code in a sequential manner, so that when one transfer finishes, another starts?










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I read this blog and found out about the file Transfer plugin. They used it to send a file(image) to the server. I want to send multiple file to a server one by one in a sequential order.






      public uploadImage() 
      // Destination URL
      var url = "http://yoururl/upload.php";

      // File for Upload
      var targetPath = this.pathForImage(this.lastImage);

      // File name only
      var filename = this.lastImage;

      var options =
      fileKey: "file",
      fileName: filename,
      chunkedMode: false,
      mimeType: "multipart/form-data",
      params : 'fileName': filename
      ;

      const fileTransfer: TransferObject = this.transfer.create();

      this.loading = this.loadingCtrl.create(
      content: 'Uploading...',
      );
      this.loading.present();

      // Use the FileTransfer to upload the image
      fileTransfer.upload(targetPath, url, options).then(data =>
      this.loading.dismissAll()
      this.presentToast('Image succesful uploaded.');
      , err =>
      this.loading.dismissAll()
      this.presentToast('Error while uploading file.');
      );





      How can I call this code in a sequential manner, so that when one transfer finishes, another starts?










      share|improve this question













      I read this blog and found out about the file Transfer plugin. They used it to send a file(image) to the server. I want to send multiple file to a server one by one in a sequential order.






      public uploadImage() 
      // Destination URL
      var url = "http://yoururl/upload.php";

      // File for Upload
      var targetPath = this.pathForImage(this.lastImage);

      // File name only
      var filename = this.lastImage;

      var options =
      fileKey: "file",
      fileName: filename,
      chunkedMode: false,
      mimeType: "multipart/form-data",
      params : 'fileName': filename
      ;

      const fileTransfer: TransferObject = this.transfer.create();

      this.loading = this.loadingCtrl.create(
      content: 'Uploading...',
      );
      this.loading.present();

      // Use the FileTransfer to upload the image
      fileTransfer.upload(targetPath, url, options).then(data =>
      this.loading.dismissAll()
      this.presentToast('Image succesful uploaded.');
      , err =>
      this.loading.dismissAll()
      this.presentToast('Error while uploading file.');
      );





      How can I call this code in a sequential manner, so that when one transfer finishes, another starts?






      public uploadImage() 
      // Destination URL
      var url = "http://yoururl/upload.php";

      // File for Upload
      var targetPath = this.pathForImage(this.lastImage);

      // File name only
      var filename = this.lastImage;

      var options =
      fileKey: "file",
      fileName: filename,
      chunkedMode: false,
      mimeType: "multipart/form-data",
      params : 'fileName': filename
      ;

      const fileTransfer: TransferObject = this.transfer.create();

      this.loading = this.loadingCtrl.create(
      content: 'Uploading...',
      );
      this.loading.present();

      // Use the FileTransfer to upload the image
      fileTransfer.upload(targetPath, url, options).then(data =>
      this.loading.dismissAll()
      this.presentToast('Image succesful uploaded.');
      , err =>
      this.loading.dismissAll()
      this.presentToast('Error while uploading file.');
      );





      public uploadImage() 
      // Destination URL
      var url = "http://yoururl/upload.php";

      // File for Upload
      var targetPath = this.pathForImage(this.lastImage);

      // File name only
      var filename = this.lastImage;

      var options =
      fileKey: "file",
      fileName: filename,
      chunkedMode: false,
      mimeType: "multipart/form-data",
      params : 'fileName': filename
      ;

      const fileTransfer: TransferObject = this.transfer.create();

      this.loading = this.loadingCtrl.create(
      content: 'Uploading...',
      );
      this.loading.present();

      // Use the FileTransfer to upload the image
      fileTransfer.upload(targetPath, url, options).then(data =>
      this.loading.dismissAll()
      this.presentToast('Image succesful uploaded.');
      , err =>
      this.loading.dismissAll()
      this.presentToast('Error while uploading file.');
      );






      typescript ionic3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 6:50









      stormblessed

      188




      188






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          You don't need cordova-plugin-file-transfer plugin to transfer files. You can achieve this using XMLHttpRequest Native Browser API.



          Below URL explains the various ways, we are transfer files to backend using XMLHTTPRequest API.



          https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html






          share|improve this answer



























            up vote
            0
            down vote













            I'm going to assume that you have an action like a button click that triggers the upload.



            • Maintain a JSON array. Each individual item containing data that you need for
              the upload such as file name, file locations, destination url.

            • On every click of the upload button, push another item into this array.

            • Run a loop through the JSON array. For every item, call the upload
              function. All data that you need for the upload, already exists in
              the array item.

            • Once the upload is successful, remove that item from
              the array.





            share|improve this answer




















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236680%2fhow-can-i-upload-file-images-one-by-one-in-a-sequential-manner-in-the-backgrou%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              You don't need cordova-plugin-file-transfer plugin to transfer files. You can achieve this using XMLHttpRequest Native Browser API.



              Below URL explains the various ways, we are transfer files to backend using XMLHTTPRequest API.



              https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html






              share|improve this answer
























                up vote
                0
                down vote













                You don't need cordova-plugin-file-transfer plugin to transfer files. You can achieve this using XMLHttpRequest Native Browser API.



                Below URL explains the various ways, we are transfer files to backend using XMLHTTPRequest API.



                https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  You don't need cordova-plugin-file-transfer plugin to transfer files. You can achieve this using XMLHttpRequest Native Browser API.



                  Below URL explains the various ways, we are transfer files to backend using XMLHTTPRequest API.



                  https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html






                  share|improve this answer












                  You don't need cordova-plugin-file-transfer plugin to transfer files. You can achieve this using XMLHttpRequest Native Browser API.



                  Below URL explains the various ways, we are transfer files to backend using XMLHTTPRequest API.



                  https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 10 at 7:54









                  Suresh Kumar Ariya

                  4,0551215




                  4,0551215






















                      up vote
                      0
                      down vote













                      I'm going to assume that you have an action like a button click that triggers the upload.



                      • Maintain a JSON array. Each individual item containing data that you need for
                        the upload such as file name, file locations, destination url.

                      • On every click of the upload button, push another item into this array.

                      • Run a loop through the JSON array. For every item, call the upload
                        function. All data that you need for the upload, already exists in
                        the array item.

                      • Once the upload is successful, remove that item from
                        the array.





                      share|improve this answer
























                        up vote
                        0
                        down vote













                        I'm going to assume that you have an action like a button click that triggers the upload.



                        • Maintain a JSON array. Each individual item containing data that you need for
                          the upload such as file name, file locations, destination url.

                        • On every click of the upload button, push another item into this array.

                        • Run a loop through the JSON array. For every item, call the upload
                          function. All data that you need for the upload, already exists in
                          the array item.

                        • Once the upload is successful, remove that item from
                          the array.





                        share|improve this answer






















                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          I'm going to assume that you have an action like a button click that triggers the upload.



                          • Maintain a JSON array. Each individual item containing data that you need for
                            the upload such as file name, file locations, destination url.

                          • On every click of the upload button, push another item into this array.

                          • Run a loop through the JSON array. For every item, call the upload
                            function. All data that you need for the upload, already exists in
                            the array item.

                          • Once the upload is successful, remove that item from
                            the array.





                          share|improve this answer












                          I'm going to assume that you have an action like a button click that triggers the upload.



                          • Maintain a JSON array. Each individual item containing data that you need for
                            the upload such as file name, file locations, destination url.

                          • On every click of the upload button, push another item into this array.

                          • Run a loop through the JSON array. For every item, call the upload
                            function. All data that you need for the upload, already exists in
                            the array item.

                          • Once the upload is successful, remove that item from
                            the array.






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 10 at 8:05









                          Delwyn Pinto

                          1407




                          1407



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236680%2fhow-can-i-upload-file-images-one-by-one-in-a-sequential-manner-in-the-backgrou%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Kleinkühnau

                              Makov (Slowakei)

                              Deutsches Schauspielhaus