ConnectyCube / connectycube-js-sdk-releases

Releases materials for ConnectyCube JS SDK platform https://connectycube.com
9 stars 2 forks source link

Url Attached Files on Message are not legible #88

Closed alxx28 closed 3 years ago

alxx28 commented 3 years ago

I have this fragment to receive files:

ConnectyCube.chat.onMessageListener = onMessage;

function onMessage(userId, message) {
            console.log('[ConnectyCube.chat.onMessageListener] callback:', userId, message);
            var dv_message = $('#dv_mensajeschat');

            if (message.extension.hasOwnProperty('attachments')) {
                if (message.extension.attachments.length > 0) {
                    const fileUID = message.extension.attachments[0].uid;
                    const fileUrl = ConnectyCube.storage.privateUrl(fileUID);
                    const type = message.extension.attachments[0].type;
                    if (type == 'image') {
                        dv_message.append('<div style="margin:2px;padding:2px;background-color:#EFF7FA;"><b>Paciente:</b><br><div style="text-align:center;"><a href="' + message.extension.attachments[0].url + '" target="_blank"><img src="' + message.extension.attachments[0].url + '" alt="photo" style="width:20%;height:20%"/></a></div></div>');
                    }

                    if (type == 'data') {
                        dv_message.append('<div style="margin:2px;padding:2px;background-color:#EFF7FA;"><b>Paciente:</b> <a href="' + message.extension.attachments[0].url + '" target="_blank">Ver Archivo</a></div>');
                    }
                    console.log('=>' + JSON.stringify(message.extension.attachments[0]));
                }
            } else {
                if (message.body) {
                    dv_message.append('<div style="margin:2px;padding:2px;background-color:#EFF7FA;"><b>Paciente:</b> ' + message.body + '</div>');
                }
            }
            dv_message.find('.msj_isTyping').remove();
            dv_message.scrollTop(dv_message[0].scrollHeight);
        }

The problem is that the urls that represent and image or pdf file does not allow to view the image or the pdf file in a new tab.

I am getting urls of this type: https://api.connectycube.com/blobs/D72F4375BE3613E70D5D2EA023605EB08E9D

How do I convert this url in a legible file to view it in a new tab in the browser?

1

DaveLomber commented 3 years ago

It allows either to download the file or you can show it inside HTML element

Are you looking for anything different?

alxx28 commented 3 years ago

@DaveLomber For Images works inside HTML element, but for a PDF a I am doing this and does not work:

dv_message.append('');

This is the downloaded file: image

And I have manually to put the extension "PDF" to be able to view it.

image

The same thing occurs with the images.

alxx28 commented 3 years ago

I solved it with this: https://blog.jayway.com/2017/07/13/open-pdf-downloaded-api-javascript/, taking this solution I can open the PDF file in a new tab in the browser.