Reputation: 1304
I have created a Logic app where I get emails from a Gmail Account and I want to post the attachment of the email to my rest API. But I don't understand which type I get as the attachment. I have seen: if I use the Outlook.com trigger I get a base64String but from Gmail I get something else. Is there an example how to work with Gmail attachments.
Upvotes: 2
Views: 1758
Reputation: 1304
Thanks for the input SahadevSinh. I have changed my workflow like this:
And in my endpoint I do this:
public async System.Threading.Tasks.Task<MissionOutputDto> CreateMissionFromMail(HttpRequestMessage req)
{
string body = await req.Content.ReadAsStringAsync();
dynamic fileData = JObject.Parse(body);
string email = fileData.email;
JArray files = fileData.files;
string fileString = null;
string fileName = null;
string mimeType = null;
foreach (dynamic file in files)
{
fileString = file.ContentBytes;
fileName = file.Name;
mimeType = file.ContentType;
}
Upvotes: 2
Reputation: 101
i have to one example to show you how you can get gmail attachment
1) receive email trigger :
2) get email details :
3) pass attachment details in HTTP request Step 3 details
[
{
"Name": "test (2).txt",
"ContentBytes": "dGVzdA==",
"ContentType": "text/plain; charset=\"US-ASCII\"; name=\"test (2).txt\"",
"ContentId": "",
"Size": 4
},
{
"Name": "test (2) - Copy.txt",
"ContentBytes": "dGVzdA==",
"ContentType": "text/plain; charset=\"US-ASCII\"; name=\"test (2) - Copy.txt\"",
"ContentId": "",
"Size": 4
}
]
"contentbyte" : is base64Strig
WebAPI changes :
you have create one more class to retrieve this attachment data
public class GmailAttechment
{
public string FileName { get; set; }
public string ContentBytes { get; set; }
public string ContentType { get; set; }
public string ContentId { get; set; }
public int Size { get; set; }
}
this class use to retrieve attachment details from your request
add above class into your webapi request parameter
public class GetEmailDetails { public string file { get; set; }
public string fileName { get; set; }
public string from { get; set; }
public string mimeType { get; set; }
**public List<GmailAttechment> GmailAttechmentList { get; set; }**
}
public void GetGmailDetails(GetEmailDetails gmailDetails) { foreach (var item in gmailDetails.GmailAttechmentList) { //here you can get all file content string base6String = item.ContentBytes; } }
Upvotes: 1