File upload to one drive

Sanju Varghese 21 Reputation points
2021-07-07T13:45:42.643+00:00

Hi all,

I am trying to create a flow which runs daily and picks up files in a sharepoint folder and uploads them to users one drive. For example, if a file is created in the folder with metadata of a user such as his email id (in a custom column), the flow must upload that document to that users one drive for business .
I am referring documentation from https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0
to upload file currently to my one drive in a trial tenant.
I created an Azure app
112596-image.png

which has below permissions

112577-image.png

Not sure if all these permission are required as i kept adding them depending on errors I got.
Anyway in my flow using http call, I can get the access token. I am then using https://graph.microsoft.com/v1.0/drives/{drive}/items/{itemId}:/{fileName}:/createUploadSession to get the upload url where {drive} is my one drive id, {itemId} is the onedrive folder id and {fileName} is the name of the file with extension.
After that I am using the upload url in the put request as follows but it fails and in the result of the put request, I can see

{
"error": {
"code": "unauthenticated",
"message": "Unauthenticated"
}
}

What is wrong? I am trying to upload the entire file in a single go and not divide it into multiple fragments.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,677 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,969 questions
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,031 Reputation points
    2021-07-09T08:21:39.507+00:00

    Hi @Sanju Varghese ,

    Use https://graph.microsoft.com/v1.0/sites and https://graph.microsoft.com/v1.0/drives are the same, it doesn't matter.

    Per my knowledge, the error "Content Range header is missing or malformed" means that the value of Content Range is incorrect. It could be that the file size in bytes in Content Range header doesnot math the file content size in body. It seems that when using get file content action in flow, the size of the file content is different from the file size.

    If you want to copy files from sharepoint folder to users' onedrive, you could just use the copy files action directly. It's much easier to achieve. As the below picture shows:

    113304-image.png


    If an Answer 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.


1 additional answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,031 Reputation points
    2021-07-08T06:22:31.81+00:00

    Hi @Sanju Varghese ,

    I did a test in postman, everthing works fine. Please try to do the same in postman and check the result.

    Get the upload url:

    112770-image.png

    upload the file:

    112853-image.png
    112849-image.png


    If an Answer 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.


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.