Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49178

$cordovaFileTransfer - upload documents synchronously

$
0
0

@ank5 wrote:

I am using a $cordovaFileTransfer in Ionic to upload a set of documents to the server. Below is the code

//docList is an array of all the documents that need to be uploaded
docList.map(function(doc) {
              console.log('Document to upload '+doc);
              var targetPath = cordova.file.dataDirectory + doc;
              var trustHosts = true;
              var options = {
                  mimeType: "application/octet-stream",
                  headers: {
                    "Content-Type": null,
                  }
              };
                var server = nodeserver + '/upload';
                return $cordovaFileTransfer.upload(server, targetPath, options, trustHosts);
                .then(function (result) {
                   console.log("File uploaded", result);
                })
                .catch(function(error) {
                   console.log('Upload failed '+JSON.stringify(error));
                })
              })

My requirement is such that I have to do this synchronously. I don't want to upload the second document in docList array until the first document is correctly uploaded, and so on.

Is there a way to make the upload operation synchronous?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49178

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>