cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AaronRichardson
Resolver I
Resolver I

Create file in SPO document library using HTTP request

I'm trying to build a flow that creates a file in a SharePoint document library using the Send an HTTP request to SharePoint action. I'm using this action because I want the document library to be dynamic, and the Create File action doesn't appear to allow that. 

 

My flow creates the file in the library without any errors, but when I attempt to open the file I see a message that the file isn't valid:

AaronRichardson_0-1601417257089.png

I decided to hard code a document library path and use the Create File action to compare the files once they're uploaded. This is the result:

AaronRichardson_1-1601417412329.png

 

The bottom file is created using the Create File action and opens just fine. The top file is quite a bit larger, which makes me think it isn't properly encoded. 

 

I'm pulling the file contents from PowerApps in base64 format as demonstrated here. Since both actions use the same data, I believe I'm missing something in the body of the HTTP request action. Here are the two actions:

AaronRichardson_2-1601417998181.png

 

Am I missing something in the Body of the HTTP request?

 

10 REPLIES 10
Hardesh15
Super User
Super User

@AaronRichardson 

 

Please add file extension in File name of Create file action. IF it is excel use like .xlsx

 

Thanks

Hardesh

Thanks, @Hardesh15. The file extension is already included in the variable as shown by the image of the two files that the flow created in SPO. Something else is happening to cause the file to not be created properly. 

@AaronRichardson 

Do one thing, remove your variable and type some text with extension then check.

Thanks

Hardesh

I tried your suggestion. The outcome is the same, the file is not valid. Again, I believe this has to do with the encoding or something having to do with the format of the Body in the HTTP request.

AdrianGo
Frequent Visitor

Hi Aaron,

 

did you resolve the issue?

Best,

Adrian

@AdrianGo No, I was not able to resolve the issue.

Hi Aaron & @AdrianGo 

You can successfully submit this request by changing your headers. 

Accept: application/json; odata=nometadata,
Content-Type: application/json; odata=nometadata

When you set the odata to verbose, you have to provide the metadata and type in the body.

Hi Illmatic,

 

the problem is not about submit the request, but with content of the file which is passed via variable. Variable changes encoding to UTF-8 I believe so the file content is broken.

liridonuka
Frequent Visitor

I would suggest to use payload data from Create file connector and there you will find body JSON which you can use in HTTP Request body 

 

liridonuka_0-1635280274175.png

 

Christoph15
Helper I
Helper I

Has anyone managed to get this working yet? Also the last tip didn't result in the file being corrupted.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (5,491)