Where do we retrieve the encryption key of the user
I am trying to access images. Docs say use an encryption key from the user. All we have is an access_token.
When and where do we retreive this encryption key? Using Platform API, not chat SDK
Where do we retrieve the encryption key of the user
I am trying to access images. Docs say use an encryption key from the user. All we have is an access_token.
When and where do we retreive this encryption key? Using Platform API, not chat SDK
Please refer to this link:
I guess what you are looking for is related to this parameter require_auth when sending a file:
When you then list your messages, you should have one of the attributes in the resulting JSON with a URL including this auth=XXXX
@walter.rodriguez spent some time this weekend and could not find any messages with an auth=xxx assigned. can you please advise? is it possible to disable this requirement for our account?
If your URL needs authorization, you can download it using your Api-Token (you get it from your Sendbird Dashboard). This is an example using Javascript:
var url = message.plainUrl; // This is the URL from Sendbird which needs authorization
var headers = new Headers({
'Api-Token': 'YOUR-API-TOKEN'
});
var options = {
method: 'GET',
headers: headers,
mode: 'cors',
cache: 'default'
};
var request = new Request(url);
fetch(request, options).then((response) => {
response.arrayBuffer().then((buffer) => {
var base64Flag = 'data:' + message.type + ';base64,';
var imageStr = arrayBufferToBase64(buffer);
// <img src="${ base64Flag + imageStr }" /> // This will show an image file
});
});
And then, for the arrayBufferToBase64
function:
function arrayBufferToBase64(buffer) {
var binary = '';
var bytes = [].slice.call(new Uint8Array(buffer));
bytes.forEach((b) => binary += String.fromCharCode(b));
return window.btoa(binary);
}
If you are downloading another format (let’s say a PDF file):
fetch(request, options).then((response) => {
console.dir( response ); // Check the full response object
console.log( response.url ); // This is the URL to download
// Download automatically
var a = document.createElement('a');
a.href = url;
a.download = fileName;
a.click();
})