i'm trying to use the mulesoft slack connector to upload a pdf file and a png file to a slack channel but i'm not able to configure the settings correctly to make this work. Has anyone been able to do so successfully? Here is my transform message just before the slack upload file connector:
%dw 2.0
output application/x-www-form-urlencoded
---
{
"channels": "C03E4FWEQRY",
"content": payload,
"filename": "AdobePremierPro2021.pdf",
"title": "AdobePremierPro2021",
"filetype": "pdf"
}
It sends the file to the channel but all content is lost. The file comes across as a binary file that cannot be read.
Here is the XML snippet:
<flow name="upload-sub-flow" doc:id="1c8a2b29-5358-41bd-acd8-760676ddd86e" >
<file:read doc:name="Read" doc:id="d4ba9476-4d83-47cd-8915-f1e8ef8e119e" config-ref="File_Config" path="/Users/aparkhe/AnypointStudio/1platform/slack-sys-api/src/main/resources/AdobePremierPro2021.pdf"/>
"] <ee:transform doc:name="Transform Message" doc:id="72c36c3b-ce68-4c5d-8a0f-961f95a71569" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/x-www-form-urlencoded
---
{
"channels": "C03E4FWEQRY",
//"thread_ts": vars.SlackTS,
"content": payload,
"filename": "AdobePremierPro2021.pdf",
//"filename": "ArrivalPass.png",
//"title": "AdobePremierPro2021",
"filetype": "pdf"
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<slack:create-filesupload doc:name="Upload File" doc:id="08546a03-d746-42af-b50e-d45c11a5eb04" config-ref="Slack_Connector_Config"/>
</flow>
Here is the POM dependency:
<dependency>
<groupId>com.mulesoft.connectors</groupId>
<artifactId>mule4-slack-connector</artifactId>
<version>1.0.12</version>
<classifier>mule-plugin</classifier>
</dependency>
It seems like the slack connector is not enough matured yet, and is having problem with binary data. The file.upload endpoint of Slack supports two MIME types, application/x-www-form-urlencoded and other multipart/form-data. After checking the debug logs, it looks like the slack connector is only using the application/x-www-form-urlencoded encoding, which is not the best usecase for sending binary data.
I will recommend you to use either of these options:
slack connector community version: It works great with similar configuration. You will not have to worry about the request structure as it will encapsulate everything. Also it uses multipart/form-data under the hood so you will not have any issues with PDF or PNG files. The usage is extremely simple so I will not add the details here. You will be able to understand it as soon as you drag the component.
Use the traditional http:request connector. The tricky part here is to create the multipart/form-data payload. However you can use the Multipart dataweave module that will make it fairly simple.
You will use Multipart::form function to create the form, and pass an array of the 4 fields, that you were setting in your transform message, using Multipart:field function.
Your transform module will look like this
%dw 2.0
import dw::module::Multipart
output multipart/form-data
---
Multipart::form([
Multipart::field("channels","#testing"),
Multipart::field("filename","AdobePremierPro2021"),
Multipart::field("filetype","pdf"),
Multipart::field("file",payload, "application/pdf", "AdobePremierPro2021.pdf"),
])
The payload here will be the output of the file:read operation
Related
I am working on a Microsoft Teams chat bot using Microsoft Bot Framework. The bot sends an Adaptive Card containing some text and the following Action:
{
"type": "ActionSet",
"actions": [
{
"type": "Action.OpenUrl",
"title": "View in dashboard",
"url": "${url}"
}
]
},
The URL is of the following form (edited to remove identifying info):
https://internaldomain.net/dashboard/share/134590h9?overrides=[{"query":"//dataSources","key":"account","replacement":"accountName"},{"query":"//*[id='Cluster']","key":"value","replacement":"clusterId"},{"query":"//*[id='NodeId']","key":"value","replacement":"nodeId"},{"query":"//*[id='ContainerId']","key":"value","replacement":"containerId"}]&globalStartTime=1591552800000&globalEndTime=1592460000000&pinGlobalTimeRange=true
The URL is generated and passed into the url property using a JSON templating library, and I can print the URL in the console so I know it is set properly. Also, I can run the bot in the Emulator and open the link that way. However, when I run the bot in Teams and try to open the same exact link by clicking the action button, nothing happens. If I change what URL is passed in, e.g. using https://internaldomain.net/dashboard, the link works correctly.
One thought is that the generated URL is formatted improperly so Teams doesn't recognize it or open it. But I can paste it into a browser and it opens properly.
Another thought is that the URL length (almost 500 chars) exceeds some limit for Adaptive Cards, but I haven't been able to find any info about that in the documentation or online.
I would appreciate any other ideas about what might be causing this.
Thanks!
It looks like you're needing to encode the urls before embedding them - probably the {"query" etc. is conflicting with the final Json. It looks like you're using .Net, so you could call WebUtility.UrlEncode, on everything from "?" onwards (i.e. "?overrides...")
When I open email message in the office365 web browser page, there is an option to DOWNLOAD contents of the attached to this email itemAttachment ( another message attached to the current one using Microsoft Outlook ) - *.eml file, (contentType: RFC-822).
However, when I'm trying to get the contents of this itemAttachment through Graph API (same operation), the contentBytes response property is not present.
{
"#odata.context": "https://graph.microsoft.com/beta/$metadata#users('bbbbb')/messages('fffff')/attachments",
"value": [{
"#odata.type": "#microsoft.graph.itemAttachment",
"id": "gggg",
"lastModifiedDateTime": "2017-02-13T16:29:45Z",
"name": "The Daily Build - Compiling your C code to .NET",
"contentType": "message/rfc822",
"size": 99129,
"isInline": false
}
]
}
Any ideas how to get contents of attached outlook message though Graph API ( contentType=itemAttachment )? The fileAttachment contentType is working fine, I can grab the contents from the contentBytes property of the Graph API response. The following API endpoints are considered:
https://graph.microsoft.com/beta/me/messages/{id}/attachments
https://graph.microsoft.com/beta/me/messages/{id}/attachments/{attachmentId}
https://graph.microsoft.com/beta/me/messages/{id}/attachments/{attachmentId}?$expand=#microsoft.graph.itemAttachment/item
neither of the above returns contents of the attached Item.
It's in beta and there isn't a documentation, but you can get MIME content with Microsoft Graph API:
GET https://graph.microsoft.com/beta/me/messages/{id}/$value
or
GET https://graph.microsoft.com/beta/users/{id | userPrincipalName}/messages/{id}/$value
Attachments:
GET https://graph.microsoft.com/beta/users/{id}/messages/{id}/attachments/{id}/$value
With the response you can create a file with .eml extension.
Edit:
Now it's officially in preview: https://learn.microsoft.com/en-us/graph/outlook-get-mime-message
My app uses Google API client library for .NET to send emails with attachments.
When using Send(), I'm facing some limitations when it comes to file size of the attachments. So, I guess switching to Resumable upload as upload method may help. But it's pretty much undocumented.
Looking into source code, I guess using different Send() overload may be the way forward, but I can't figure out how to use it properly.
So, instead of attaching the files into message and calling it like this:
var gmailResult = gmail.Users.Messages.Send(new Message
{
Raw = base64UrlEncodedMessage
}, "me").Execute();
I should not attach the files to message and do something like following?
var gmailResult = gmail.Users.Messages.Send(new Message
{
Raw = base64UrlEncodedMessage
}, "me", fileStream, contentType).Upload();
The second version does not return any API error, but does nothing. I'm obviously missing something here.
How do I attach more than one attachment?
This is kind of an old question, but putting an answer here just in case anyone else needs it:
I was able to achieve this by converting my mime message into a stream (attachment(s) included), and then calling this overload on Send:
UsersResource.MessagesResource.SendMediaUpload googleSendRequest = service.Users.Messages.Send(null, "youremail#gmail.com", mimeMessageStream, "message/rfc822");
IUploadProgress created = googleSendRequest.Upload();
This will upload all of the attachments with the email message content and then send it off. I was able to send two 5 megabyte attachments in an email. Previously I was not able to send even one of those via the other Send method that takes in a base64 encoded mime message.
I have a textarea with html id "id_textarea".
editor = CKEDITOR.inline( 'id_textarea', {
filebrowserBrowseUrl : 'browse_url',
filebrowserUploadUrl : 'upload_url'
});
editor.on( 'fileUploadRequest', function( evt ) {
console.log("This is not printing");
});
Whenever I try to upload a file, it doesn't print anything to console. Am I doing something wrong?
By the way, my requirement is to add csrf headers before sending a request for which I need to catch some event like fileUploadRequest.
I assume that you are trying to upload files via the Upload tab in the Image Properties dialog. It is provided by the File Browser plugin and fileButton which does not support the fileUploadRequest and fileUploadResponse events (there is already a feature request with a more in-depth description of this case).
If you would like to use these events for some custom request preprocessing, you can use the Upload Image plugin. The configuration process is described in the official docs, but keep in mind that it will work only for dropping or pasting files. Upload via the Image Properties dialog will still be handled by the File Browser plugin which does not support these events.
The important thing here is that since CKEditor 4.5.6, the File Browser plugin uses the CSRF header so it can be probably used on your server side without any modifications in the JavaScript code. So if you are using an older version I suggest updating to 4.5.6 (using e.g. CKBuilder) and trying to integrate with your backend. The CSRF header in the File Browser plugin should be sufficient for your needs.
Here is the header:
We are developing an GWT web-application with an Python webapp2 webserver. At this point we want to load and save files within the web-application. We cannot use Flash for this task.
Saving
The current approach is to use a form upload using the target "_blank" and set the correct MIME to make the browser download the file. This solution works, but since the webapp2 webserver does not support streaming (thus the mime type cannot be validated by the browser in a short time), a new browser-window is opened each time. Is there a better solution e.g. using iFrames?
Loading
Again using form upload and parsing the response (JSON). We use the content-type "text/html; charset=UTF-8". This solution works perfectly in IE9 but does not work in Chrome and FireFox. It seems, that the JSON response gets corrupted in some way or is there anything from when parsing a JSON response from a form upload response? We use piriti for JSON (de)serialization.
For loading, you can use RestyGWT library, it has capability encoding or decoding Java Object to JSON:
import javax.ws.rs.POST;
...
public interface PizzaOrderCodec extends JsonEncoderDecoder<PizzaOrder> {
}
// GWT will implement the interface for you
PizzaOrderCodec codec = GWT.create(PizzaOrderCodec.class);
// Encoding an object to json
PizzaOrder order = ...
JSONValue json = codec.encode(order);
// decoding an object to from json
PizzaOrder other = codec.decode(json);
For saving, if you have to send JSON file using file upload, you can see following link:
http://www.jroller.com/hasant/entry/fileupload_with_gwt
http://www.celinio.net/techblog/?p=1207
Have a nice time.