Issues with OneDrive Direct Link Conversion

陳 藝禾 0 Reputation points
2024-12-13T12:29:06.07+00:00

Hello,

I have been successfully using a method to convert OneDrive direct links into a Base64 encoded URL to share content via API, like this:

Original URL:

https://1drv.ms/t/c/b6a769b937e9eff3/EVtvodt7gEhKleFWNTy55vgBTFOziVeKp3kMvqG1wrrROA

Converted Base64 URL:

https://api.onedrive.com/v1.0/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL3QvYy9iNmE3NjliOTM3ZTllZmYzL0VWdHZvZHQ3Z0VoS2xlRldOVHk1NXZnQlRGT3ppVmVLcDNrTXZxRzF3cnJST0E/root/

This was working fine previously. However, recently when I try to access the converted URL, I get the following error:

Error:

{"error":{"code":"unauthenticated","message":"Exception of type 'Microsoft.Vroom.Exceptions.UnauthenticatedVroomException' was thrown."}}

I'm using the following function to encode the URL into Base64:

function encodeBase64Url(url) {

const base64Encoded = btoa(url);  // Base64 encode the URL

const base64Url = base64Encoded

    .replace(/\+/g, '-')  // Replace '+' with '-'

    .replace(/\//g, '_')  // Replace '/' with '_'

    .replace(/=+$/, '');  // Remove '=' padding

return `u!${base64Url}`;  // Add 'u!' prefix

}

const encodedUrl = encodeBase64Url(url);

// Create the download link

const downloadLink = https://api.onedrive.com/v1.0/shares/${encodedUrl}/root/content;

Is there something wrong with my conversion process, or is there a different issue causing the error? Any help in resolving this would be greatly appreciated!

OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,322 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emi Zhang-MSFT 28,746 Reputation points Microsoft External Staff
    2024-12-16T01:12:13.8766667+00:00

    Hi,

    I suggest you post this thread to OneDrive for Developer forum:

    https://techcommunity.microsoft.com/category/onedriveforbusiness/discussions/onedrivedeveloper

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.