question

SanjuVarghese-8982 avatar image
0 Votes"
SanjuVarghese-8982 asked MichaelHan-MSFT edited

File upload to one drive

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://docs.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.

office-sharepoint-onlinesharepoint-dev
image.png (5.3 KiB)
image.png (37.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered SanjuVarghese-8982 commented

Hi @SanjuVarghese-8982,

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.



image.png (23.9 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

When I see the output of the get file content in flow, it shows the exact same content length and also content range. So I don't think it is different. But thanks for the copy file action, I was able to copy large files too to another users one drive

0 Votes 0 ·
MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered SanjuVarghese-8982 edited

Hi @SanjuVarghese-8982,

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.



image.png (101.2 KiB)
image.png (107.1 KiB)
image.png (40.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MichaelHan-MSFT ,

I I noticed that your Get upload url starts with https://graph.microsoft.com/v1.0/sites where as mine Get upload url starts with https://graph.microsoft.com/v1.0/drives. I am confused. I want to upload from sharepoint to onedrive. So should I use https://graph.microsoft.com/v1.0/sites OR https://graph.microsoft.com/v1.0/drives ?

It works in postman, I am able to upload the file. But however when I try in PowerAutomate with hardcoded content length and Content Range , it gives an error "Content Range header is missing or malformed"

113022-image.png

113023-image.png

Please advise


0 Votes 0 ·
image.png (34.5 KiB)
image.png (40.1 KiB)