I'm trying to use the file upload API, but I don't know what's causing the error.

taewoo.Oh 45 Reputation points
2023-09-14T23:30:13.7966667+00:00

hello,

I want to use the upload API in Graph REST API.

I set Content-Type: text/plain according to the official document, but an error like the picture occurs. Does anyone know why?

업로드

This is the code I wrote. Is there a problem with your code?

async _createUrlFile(){
        const url = `[InternetShortcut] 
                     URL =`+ this.userValue;
        console.log(url);
        const blobFile = new Blob([url],{type: 'text/plain'});
        console.log(blobFile);
        let res = await fetch('https://graph.microsoft.com/v1.0/drives/01TMG2GIK5NDAVZY67M5BIFFZHNASXBVBY/items/01TMG2GIKC7HQGCO7RGBEZCQKDPLQ4G7NG/testFile.url:/content',{
            method : "PUT",
            headers:{
                'Authorization': 'Bearer ' + this.TOKEN,
                'Content-Type': 'text/plain'
            },
            body : {
                blobFile
            }
        
        })
        const data = await res.json();
        console.log(data);
    };
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,829 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,205 questions
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 41,286 Reputation points
    2023-09-15T07:30:29.2333333+00:00

    Hi @taewoo.Oh

    The content-type header is not required, you can try removing 'Content-Type': 'text/plain' from your script.


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.