OneDrive / samples

Contains samples, scenarios, and guidance for integrating with OneDrive and SharePoint drives, drive items, and files.
MIT License
58 stars 59 forks source link

No Download File Url #2

Closed bhavens17 closed 1 year ago

bhavens17 commented 2 years ago

I've implemented the Javascript client logic into my app and can successfully show the file picker to a user and allow them to select file(s) from their OneDrive, however when I receive the file information in the message handler after selecting the files there doesn't appear to be a 'Download Url' value. I was expecting to receive a '@microsoft.graph.downloadUrl' (or similar) value. The values that I'm receiving instead are:

@sharePoint.embedUrl: "XXX"
@sharePoint.endpoint: "XXX"
@sharePoint.listUrl: "XXX"
folder: "XXX"
id: "XXX"
name: "XXX"
parentReference: {...}
size: XXX
webDavUrl: "XXX"
webUrl: "XXX"

Is there a certain param value that's required in order to get a download URL for the selected files? Or some other way to retrieve this information?

My current params are:

const params = {
        sdk: "8.0",
        entry: {
            oneDrive: {
                files: {},
            }
        },
        authentication: {},
        selection: {
            mode: 'multiple'
        },
        messaging: {
            origin: "https://localhost",
            channelId: "27"
        },
        typesAndSources: {
            mode: "files",
            pivots: {
                oneDrive: true,
                recent: false,
                sharedLibraries: true
            },
        },
    };
patrick-rodgers commented 2 years ago

I don't believe the download url is included, you can see this samples where we use the webDavUrl value to run the download. Alternatively, you can make a request to the graph drive item and get additional details that way (though I recognize that is an extra request).

bhavens17 commented 2 years ago

I did try to go the route of using the access token used during the file picker process as a bearer auth token w/ the webDavUrl to request the selected files, but was getting an unauthorized response for that. Was just hoping to avoid having to run a second process to actually download the file.

AnkitBajpaii commented 1 year ago

I faced the exact same issue and as a work around, here's what i did: After I selected the file(s) from file picker, I extracted the selected file Id's and then made an api call to microsoft graph end point (/me/drive) for each file id to get '@microsoft.graph.downloadUrl' for each file . @patrick-rodgers Ideally this should be included in pick command. The file picker should give this pre-authenticated download url

ghost commented 1 year ago

@microsoft.graph.downloadUrl from the selected files is valid only for an hour. It is mentioned in documentation. Documentation link: Link

image

patrick-rodgers commented 1 year ago

Going to close this as the returned object contains enough information to construct a valid Graph URL to get the file contents without the presence of the @microsoft.graph.downloadUrl field.

Recently updated docs describe this. To get the content you can add /content.

GET @sharePoint.endpoint + /drives/ + parentReference.driveId + /items/ + id + /content