0

When doing a resumable upload to a file that was shared the url returned from createUploadSession can not be used.

Uploading directly with /content works but has a limit of 4MB

Scenario UserA shares a file with edit permissions to UserB Using the ms graph javascript sdk

const { uploadUrl } = await this.client.api(`/drives/${driveId}/items/${id}/createUploadSession`).post({});

trying to use uploadUrl results in a 404 {"error":{"code":"itemNotFound","message":"The resource could not be found."}}

Interestingly the uploadUrl looks something like this https://{tenant}-my.sharepoint.com/personal/{UserA}_{tenant}_com/_api/v2.0/drives/${driveId}/items/${id}/uploadSession?guid='5b85df9e-b524-4000-9883-8106a13e592f'...

Not sure if its related to UserA being embedded in the url or not.

If UserA accesses the same file and does a similar upload everything works fine on the file.

All of the following requests work fine for either User:

await this.client.api(`/drives/${driveId}/items/${id}/checkout`).post({});
await this.client.api(`/drives/${driveId}/items/${id}/content`).putStream(fs.createReadStream(filePath));
await this.client.api(`/drives/${driveId}/items/${id}/checkin`).post({});

uploadUrl returned from createUploadSession should be valid for any user that had access to create an upload session.

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
asnyder
  • 1
  • 1

1 Answers1

0

You cannot upload/replace files shared from another user's OneDrive. Creating an upload session creates a temporary file in the Drive for writing each chunk. Since User B doesn't have read/write access to User A's OneDrive, they cannot create that temporary file (thus the 404 - Not Found).

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
  • This doesn’t logically make sense to me, if I am sharing a file with read/write access why can’t I make changes to the file? Why am I able to upload directly to the file outside of an upload session? I am trying to create a custom file handler for my file type I want to offer the same experience as office products from the sounds of it I can if the file is under 4mb since an upload session is not required, but for files larger this isn’t supported? What are the possible work arounds ? Can I write a temporary file to /me and then copy the file overtop the other? – asnyder Nov 09 '19 at 22:19
  • This sounds more like a shortcoming with how uploadsession were implemented, that have leaked into incorrect API behavior. I don't see this specifically being documented as a restriction of upload sessions – asnyder Nov 09 '19 at 22:34
  • 1
    Since I don't own those APIs, I can't really speak to how they were implemented or why. I can only speak to my understanding of the existing behavior. – Marc LaFleur Nov 10 '19 at 03:36