3

so i have been trying to save a file to onedrive by converting the file data to

datauri and uploading instead of using the sourceInputElementID

so i am converting the file uploaded to dataURL format using a file reader and then passing that as the source uri

code :

<html>
  <head>

    <script type="text/javascript" src="https://js.live.net/v7.0/OneDrive.js"></script>

      <script type="text/javascript">

        var openfile= function(event){

             var input= event.target;
             var reader=new FileReader();

              var launchSaveToOneDrive= function (dataURL){
                       console.log("2");
                      var odOptions = {
                          clientId: "1fd8b6bd-4585-4491-a802-7bc9f0fde5da",
                          action: "save",
                       // sourceInputElementId: "",
                          sourceUri: dataURL,
                          fileName: "fil.txt",
                          openInNewWindow: true,
                          advanced: {},
                          success: function(files) { console.log('success');},
                          progress: function(p) { console.log("2"); },
                          cancel: function() {console.log("3"); },
                          error: function(e) { console.log(e); }
                        }
                        console.log("3");
                      OneDrive.save(odOptions);
                    };


              reader.onload= function() {
                launchSaveToOneDrive(reader.result);
                console.log("1");
              }
              reader.readAsDataURL(input.files[0]);
        }
</script>
</head>
<body>
    <input id="fileUploadControl" name="fileUploadControl" type="file" onchange="openfile(event)" />

</body>
</html>

but i get this error in the console

error

error in text -

OneDrive.js:2 Uncaught TypeError: Cannot read property 'focus' of undefined
e.openPopup @ OneDrive.js:2
e.launchSaver @ OneDrive.js:3
e.save @ OneDrive.js:2
e.save @ OneDrive.js:2
launchSaveToOneDrive @ (index):29
reader.onload @ (index):34

the code is hosted on https://bandrevu-akhil.github.io/ so you can test it there.

my question is their anyway to convert the file to datauri format and upload to onedrive using sourceuri ?

0 Answers0