Anonymously uploading to a publicly shared folder

2019-04-16 20:16发布

问题:

What is the REST API call to anonymously upload to a publicly shared folder on OneDrive?

I have tried sharing a folder both thru the OneDrive Web UI creating a link attributed with: "Anyone with this link can edit this item", and using the REST API:

POST https://graph.microsoft.com/v1.0/drives/{driveId}/items/{sharedFolderId}/createLink
Content-type: application/json
{
    "type": "edit",
    "scope": "anonymous"
}

In both cases, I can read from the shared folder without logging on by

GET https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}

I can also read the permission itself using

GET https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}/permissions

=>

{
    "@odata.context":"https://api.onedrive.com/v1.0/$metadata#shares('{shareId}')/items('{sharedFolderId')/permissions",
    "value":
    [
        {
            "id":"{permissionId}",
            "link":
            {
                "application":
                {
                    "displayName":"{my own app}",
                    "id":"{short app id}"
                },
                "type":"edit",
                "webUrl":"https://1drv.ms/u/{shareId}"
            },
            "roles":["write"],
            "shareId":"{shareId}",
            "expirationDateTime":"0001-01-01T00:00:00Z",
            "hasPassword":false
        }
    ]
}

However trying to upload a file or create a subfolder, i.e.

PUT https://api.onedrive.com/v1.0/shares/{shareId}/driveItem:/{filename}:/content
Content-type: text/plain
some text goes here

or

POST https://api.onedrive.com/v1.0/shares/{shareId}/items/{sharedFolderId}/children
Content-type: application/json
{
    "name": "TestFolder",
    "folder": { }
}

both fail as unauthorized calls - but isn't the whole point of an "edit" link with "anonymous" scope that "anyone with this link can edit this item"?

I have tried various combinations of https://graph.microsoft.com/v1.0 instead of https://api.onedrive.com/v1.0 and /drives/{driveId} instead of /shares/{shareId} as well as /shares/{shareToken}, where shareToken is the "u!"-encoding of the webUrl from the link in the permission.

So far without being able to figure out the right REST API call. I hope someone is able to help :-)

You can download my TestOneDrive Visual Studio test project to reproduce the issues. It also contains initialization code to create and share the folder.

回答1:

Due to no guys from Product Group following this and no official docs announced this, so I suggest you to submit an feature request first on UserVocie or vote up an existing one close to your issue.