Hi,
I am using the code below on button click calling the function launchOneDrivePicker() , when i call it the file picker is popup in new window and i am able to select or choose the file.
<div>
<button type="button" onclick="launchOneDrivePicker();">**launchOneDrivePicker**</button>
</div>
function launchOneDrivePicker() {
var odOptions = {
clientId: "###############################",
action: "download",
multiSelect: true,
openInNewWindow: true,
advanced: {
redirectUri: "https://login.live.com/oauth20_authorize.srf?client_id=*****************&scope=onedrive_onetime.access:readfiles|single|downloadLink&response_type=code&redirect_uri=https://localhost/Onedrive/WebForm1.aspx"
},
success: function (files) { download(); },
cancel: function () { /* cancel handler */ },
error: function (e) { /* error handler */ },
};
OneDrive.open(odOptions);
}
Now my Question is that How can i download the selected file after click the Open button as mention in screen shot below:
I am going through the link below:
https://msdn.microsoft.com/en-us/library/hh550839.aspx
but i am not able to download the file I called the download function in success function but there i am not able to download please share some reference or query how can i achieve this.
Thanks.
hi @Sanjeev143 , you went to the old SDK documents, the one you are using is v7.0 which doc is here: https://dev.onedrive.com/sdk/js-v7/js-picker-open.htm
based on your option, the returned files in the success callback should looklike:
which you can get the download url from attribute "@microsoft.graph.downloadUrl"
@daboxu : thanks for the response, i follow the same url in my web app and use the sdk below:
<script type="text/javascript" src="https://js.live.net/v7.0/OneDrive.js"></script>
but when i am trying to call simple alert() function in success:
success: function (files) { alert("Response on success"); },
i am not able to get any response by alert that means it doesn't work. so how can i fire the success method. As per the documentation success function is called when file is opened or uploaded but in my case i didn't get the response at all. please see the code that i have mention in my question above ance again thanks for the response.
hi @Sanjeev143 Which SDK are you using? I saw blank in your comment. Ideally, the popup should close itself after redirected to the redirect uri you specified. In your case I saw login.live.com which is interesting because it would swallow the response in url params. Try redirect directly to your host app instead of login.live.com.
hi @daboxu thanks, now i am able to call the alert() function in success and app does the same behavior as you mention in above comment but now the problem is that when i am trying to get attribute
alert("You picked " + response.value[0][email protected]); @ is pointing to invalid character so how can i get the download url.
@Sanjeev143
response.value[0]["@microsoft.graph.downloadUrl"]
should work for you
@daboxu thanks, now i am able to download the file after call in success:
success: function (response) {
var downloadurl = response.value[0]["@microsoft.graph.downloadUrl"];
alert("You picked : " + downloadurl);
location.href =downloadurl;
alert("Download completed..");
but the problem is that the format and name of file is changed so how can i retrieve the name and file format same during download.
Thanks.
@Sanjeev143 the download url is the binary data of the file and unfortunately the File Picker SDK has no way to control over it. The download action varies from browser to browser so I would suggest you start with this: http://stackoverflow.com/questions/283956/is-there-any-way-to-specify-a-suggested-filename-when-using-data-uri and the demo
@daboxu Thanks a lot for the help I solved the problem using [web method ] and js function below:
Getting the URL and file name :
var file_name = response.value[0]["name"];
var downloadurl = response.value[0]"@microsoft.graph.downloadUrl"];
JavaScript function :
function HandleIT(downloadurl,file_name) {
PageMethods.ProcessIT(downloadurl,file_name, onSucess, onError);
function onSucess(result) {
alert(result);
}
function onError(result) {
alert('Something wrong.');
}
}
[WebMethod]
` public static string ProcessIT(string downloadURL, string file_name)
{
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
string path = @"c:\";
string path_n_name = path + file_name;
// Download the Web resource and save it into the current filesystem folder.
myWebClient.DownloadFile(downloadURL, path_n_name);
return "SUCCESS";
}`
So it's work fine for me thanks a lot once again.
good to know that, I am going to close this thread and feel free to reopen it if you have questions related in the future.