Sabyasachi Sahoo
Sabyasachi Sahoo

Reputation: 11

How can I use the OneDrive Web picker when my application contains query string

We are using grails to develop our Job portal application. We have a requirement to download the document from onedrive once the user will apply for any particular job and uploading a doc from onedrive. The URL will be different for every job ( http://localhost:8080/apply?jobId=1137. Here "apply" is a action ) from where we need to load the onedrive. I put the js code in external script file and include in the apply.gsp and my redirecturl as "http://localhost:8080/apply" in onedrive configuration. Once I am clicking on the Ondrive option, it is opening the login page in a new window and I could able to choose the file. And once I click on the "open" button, the request is hitting to the "apply" action in the controller and getting the exception in the new window itself ( getting exception as jobid is missing the new request). we are unable to get the download url also as the response is not coming back to the same page. we are using OneDrive v5 SDK.

Please help me how to fix the issue so that the new window will be closed and get the selected docs download url.

js file

function launchOneDrivePicker(){

    var pickerOptions = { 

          success: function(files) {

            // Handle returned file object(s)

            var filObj = files.values[0];
            var fileName = filObj.fileName
            var fileLink = filObj.link
            var fileSize = filObj.size

            alert("File Name : " + fileName + "  **  fileLink : "+ fileLink +"  **  fileSize : "+fileSize);
          },

          cancel: function() {
              // handle when the user cancels picking a file
          },

          linkType: "webViewLink", // or "downloadLink",
          multiSelect: false // or true
    };
    OneDrive.open(pickerOptions);
  }

Thanks

Upvotes: 1

Views: 414

Answers (1)

user3728961
user3728961

Reputation: 81

Look at the 'Using a custom redirect URI' section from the documentation page: https://dev.onedrive.com/sdk/js-v7/js-picker-open.htm


To paraphrase:

Make a new separate page containing just the OneDrive script:

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

Reference the new page as the redirect URL in the advanced section of the request

var odOptions = {
  clientId: "INSERT-APP-ID-HERE",
  action: "download",
  openInNewWindow: true,
  advanced: {
    redirectUri: "https://contoso.com/filePickerRedirect.htm" <-- new separate page
  },
  success: function(files) { /* success handler */ },
  cancel: function() { /* cancel handler */ },
  error: function(e) { /* error handler */ }
}

Remember to add the new page as an authorised redirect URL for the application.

Upvotes: 1

Related Questions