How to get multiple files using GetBobContent and add as attachment to Email in Azure Logic app? - azure

Hi I am working in Azure Logic app. I am trying to get multiple files from azure data Lake gen v2 and attach these multiple files in an email. As a first step I have added http request and I am giving required information along with file path. It works fine for one file. but I am trying to input folder path and inside that folder, all the files I want to get and attach in email.
Logic app Flow Diagram
Added sample screenshot for attachment
tried to add attchment
In the above diagram, Get blob content step which works fine for one file but I am finding difficult to attach multiple files in email. Can some one help me to figure out the solution. Any help would be appreciated. Thank you

You can use List blobs action to list all blobs in the folder you want:
Then you can define a variable to append the attachments array.
Use For Each to loop the blobs from List Blobs action. Within For Each you can use Get blob content to get blob content, and then use Append to array variable to append attachments.
The expressions of Path, DisplayName and File Content are as follows:
Path : items('For_each')?['Path']
DisplayName : items('For_each')?['DisplayName']
File Content : body('Get_blob_content')
Finally, please fill in the attachment in the email:
==========================update===================
If you send an email with 400 response, please use expression in Append to array variable as below:
base64(body('Get_blob_content'))

Related

Rest API to get the list of files inside the container/directory/ in AZURE storage

I have a container called 'services'.Inside the Container , i have a directory called 'Test'.how we can get the list of blobs inside the directory test.I have few kept few CSVs inside the test. Need the rest api to get the list of the files.
However i am able to get the list of items inside the container easily using below Rest API
https://myaccount.blob.core.windows.net/services?restype=container&comp=list
i tried
https://myaccount.blob.core.windows.net/services/Test?restype=directory&comp=list
but it is not working.
Please help to get the coorect param value or rest API to find the list of items inside the directory
https://myaccount.blob.core.windows.net/services/Test?restype=directory&comp=list&prefix=Test/
The doc:
https://learn.microsoft.com/en-us/rest/api/storageservices/list-blobs#uri-parameters
Just add a param prefix is ok.

Is there any rest end point where I can find if the id I have is a file or a folder for onedrive/sharepoint?

I have an id(fdxxxf8-6xxb-4xx0-8xx9-9xxx8) which i got from one of the API response. Is there anyway to figure it out if the id is of a file or a folder?
I need to call to different API based on if it is a folder or a file
We can use the OneDrive API like below, if the Response data contains file property, the id is of a file, if the Response data contains folder property, the id is of a folder.
/me/drive/items/{item-id}?$select=file,folder
Reference: Get a DriveItem resource

Logic Apps - for each loop with liquid from blob storage

Im learning logic apps and im trying to create a simple flow from azure blob storage, perform a liguid parsing and then save parsed file to another blob container.
How should it work:
1. Whenever new file is added to blob container ("from") [containing xml files]
2.Liquid action takes place (XML -> JSON)
3.New file .json is saved to blob container ("too") :)
What i have learned:
1. I manage to write a liguid template for xml files - tested - working
2. I know how to copy file between blob containers - tested - working
For each loop:
https://i.imgur.com/ImaT3tf.jpg "FE loop"
Completed:
https://i.imgur.com/g6M9eLJ.jpg "Completed..."
Current LA:
https://i.imgur.com/ImaT3tf.jpg "Current"
What I dont know how to do:
1. How to "insert" current file content in for each into liquid action? It looks like logic apps is skipping that step?
The main problem is you could not use Current item as the xml content, you need to get the content with Get blob content action in For_each, then parse xml to json. After this create the blob in another container with json value.
You could refer to my workflow.

Passing Dropbox file contents to an Azure Function from a Logic App

I am trying a sample app with the workflow
Wait for new file (csv) in dropbox folder
Load the file contents
Pass the file contents to an azure function to further process
I am getting stuck on how to pass the file contents to the azure function. I keep getting an unsupportedmediatype error with "Message": "The WebHook request must contain an entity body formatted as JSON
How do I get the output of the second stage into a function?
What I typically do in those scenario's is create a json-body for the Function and add the messagecontent I want to sent to the function as a Base64-string as a part of the json-body (eg. Payload, or Body).
Similar approach on how Logic Apps handles certain media types at runtime.
{"OriginalFileName" : "myfile.csv", "PayLoad" : "ContentBase64String"}

How to iterate through all files in sftp folder in Microsoft Azure Logic App

steps i already did using SFTP connector (how can i access files while looping through list files in folder in azure logic app):
I added foreach loop
I added list files in folder
I passed Body as parameter in foreach loop
then i added action to create new file with new name for all files.
but i am not able to get file name and content while iterating sftp folder using foreach loop?
Please see example image, showing the logic app design. I am iterating sftp folder posting file content to http end point:

Resources