Programmable Chat Media Filename (JS) - twilio

The Media Support docs it mentions that when sending media you can: "Optionally specify a default download filename to help your application display the media to other users.". This is done using messagingOptions in Swift however in JS I cannot find any supporting documentation on how this is done. Currently, I am sending media as follows:
channel.sendMessage({
contentType: 'image/png',
media: fs.readFileSync(media)
});
I have tried adding a filename with file, filename and name properties without any luck. As you can see the filename is empty in the Twilio console:
Any help on adding a filename is much appreciated, thanks.

The answer:
const data = new FormData();
data.append('file', blob, filename);
According to the FormData docs, you can add a filename as an option like so:
After converting the image to a Base64 string I created a blob from the binary and appended the blob to the form data as shown above. Here is my code:

Related

Images/Videos CDN URL - Detect file type/extension

I'm trying to implement Story Mention rendering according to IG messenger graph API.
IG webhooks sends the payload URL of the media as CDN URLs that are extensionless,
which means I can't detect the file type(could be any kind of image or a video file).
The purpose is to render the URL to an HTML element and to prevent saving some file extensions.
Did anybody find out how to get this information?
An example for IG CDN URL
https://lookaside.fbsbx.com/ig_messaging_cdn/?asset_id=17952754300482708&signature=AbxVoHUcW3qKGZvE0FwrbpSEKBqkYGH9wFDUY9xnywlxxek8lWtrTwE173Sxhta9jbp0bgDiL17IpyiI82vqHGNPUD1wdMUZphwQOggW-_877cCI1BxaY_aDUZ8hj5OwmHK9E8OnSybqtMVmGXCX_hBF399t1Hb44zspeL3d9NWb9rib
Python:
import requests
res = requests.head(url)
print res.headers
I was able to retrieve the content type by making a request with node-fetch.
const fetch = require('node-fetch');
const response = await fetch(mediaUrl, { method: 'HEAD' });
const contentType = response.headers.get('Content-Type');

How to get the shared file with Microsoft Graph?

I want to share files from MS OneDrive to a user via MS graph API. And user can view my shared file directly through the link. I have read the Document of Creating a sharing Link for a DriveItem and use this API to create a sharing link for my sharing files.
I wonder how to implement with MS graph API? Any suggestion and tips are welcome. Thanks
According to your description, I assume you want to get the share file by using MS Graph API.
Base on my test, We can create a shareLink for this this file.
Then we can use the following steps to get the file information by converting the shareLink.
Encoding the shareLink by using the following logic:
1)First, use base64 encode the URL.
2)Convert the base64 encoded result to unpadded base64url format by removing = characters from the end of the value, replacing / with _ and + with -.)
3)Append u! to be beginning of the string.
If you want access the shared files, you can use the following API:
GET /shares/{shareIdOrUrl}/driveItem
The shareIdOrUrl parameter is the result in step1.
This API will return all the information about the shared file.
As an example, to encode a URL in C#:
string sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');
For more detail, we can refer to this document.

Flutter post to nodejs API with image file and string field as json string

Hoping to find an example of using Flutter to send a form post to Node.js and pass a string that is JSON and an image file.
I have been trying http.MultipartRequest, but the node service does not get anything in files or fields.
Not sure what I am doing wrong, so any guidance would be great.
var _url = Uri.parse('http://$baseurl/chat/messages/send');
var request = new http.MultipartRequest('POST', _url);
request.fields['json'] = json;
request.files.add(new http.MultipartFile.fromString(widget.mychat.msgkey, myimagefile.path));
Am I missing an easier way? Tried to BASE64 encode the image and add as a string in JSON, but the server keeps crashing even after I changed the amount of client request nginx would allow. I need it to work for an image or video sent from mobile.
I was having the exact same issue. The problem is not with MultipartRequest but the nodejs server.
The body-parser module you are using in the nodejs API can not handle multipart/form-data , it can only handle x-www-form-urlencoded
The solution is : You have to use module like multer in your nodejs API
const multer = require('multer')
let upload = multer({ storage: multer.memoryStorage() });
router.route('/signup').post(upload.single('avatar'),function (req, res) {
console.log('signup page');
console.log(req.file);
console.log(req.body);
//res.status(200).json({"success": "Signup page"});
res.end('hello world');
});
Found a nice solution here http://derpturkey.com/node-multipart-form-data-explained/

Reading File on Google Drive using Dart

I created a configuration file (Simple Text File) on my Google Drive and now I would like to read it from my Chrome Packaged Dart Application. But I'm not able to get more information of the file than it's name, size etc.
For accessing Google Drive I use the google_drive_v2_api.
Any suggestion on how to get the contents of my configuration file would be great! Thanks!
I just did some test in my own chrome app, uploading and downloading a simple file:
chrome.identity.getAuthToken(new chrome.TokenDetails(interactive: true ))
.then((token){
OAuth2 auth = new SimpleOAuth2(token);
var drive = new gdrive.Drive(auth)..makeAuthRequests=true;
drive.files.insert({},content:window.btoa('hello drive!')).then((sentMeta){
print("File sent! Now retrieving...");
drive.files.get(sentMeta.id).then((repliedMeta){
HttpRequest request = new HttpRequest()..open('GET', repliedMeta.downloadUrl)
..onLoad.listen((r)=>print('here is the result:'+r.target.responseText));
auth.authenticate(request).then((oAuthReq)=>oAuthReq.send());
});
});
});
It works, but the HttpRequest to get content back seems heavy...
But i really recommend you to a take look to chrome.storage.sync if your config file size is < to 4ko... If not, you could also use the chrome SyncFileSystem API... They are both easier to use, and SyncFileSystem use Drive as backend.
This page on downloading files talks through the process for getting the contents of a file.

Send/Receive image or XML file via KSOAP

it may sounds stupid but i would like to know whether is it possible send and receive. maybe image/XML file vai kSOAP?
I have been able to transmit WebRowSet XML documents using kSOAP2.
http://roderickbarnes.com/blog/droid-chronicles-web-services-handling-complex-parameters
In this example I am sending an XML document from the web service to my Android based client. I hope this helps bro.
It is possible to send image via ksoap by following steps:
convert the Image into byte[]
add byte[] of the image as property
register SoapSerializationEnvelope with MarshalBase64() like this : new MarshalBase64().register(envelope);
call your web service which takes byte[] as parameter
Then receiving the message you can convert the receieved byte[] into image file.

Resources