twilio / twilio-conversations-demo-react

Twilio Conversations Demo Web Application
MIT License
96 stars 295 forks source link

fixed download files not working #126

Closed lesquive closed 10 months ago

lesquive commented 10 months ago

Pull Request: Fix File Download Issue

Description

This pull request addresses an issue where file downloads were inconsistent in the application. Specifically, while image downloads were functioning correctly, there were problems with the download of other file types, such as PDFs.

image

Changes Made

To resolve this issue, the following changes were implemented:

onOpen function with correct file SID and file type. It's important to set image variable as undefined otherwise the if (image) bool is true in MessageList.tsx.

      {files.map((file) => (
        <ChatAttachment
          attachmentIcon={
            !isMediaLoaded || sending ? (
              <Spinner decorative={false} title="Loading" />
            ) : (
              <DownloadIcon decorative />
            )
          }
          key={`${file.filename ?? ""}.index`}
          onClick={() => isMediaLoaded && onOpen(file.sid, undefined, file)}
        >
          <ChatAttachmentLink href="#">
            {file?.filename ?? ""}
          </ChatAttachmentLink>
          <ChatAttachmentDescription>
            {`${Math.round((file.size / Math.pow(2, 20)) * 100) / 100} MB`}
          </ChatAttachmentDescription>
        </ChatAttachment>
      ))}

Contributing to Twilio

All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.