What are some ways I can efficiently download large attachments without disrupting the user's experience?

I'm encountering some challenges with handling large attachments in my project.

Initially, I had this link code:

<a :download="scope.row.name" :href="`data:${scope.row.type};base64,${scope.row.contentBytes}`">download</a>

However, fetching attachment information from graph api is very slow due to the size of contentBytes, even though lazy loading is implemented on onclick event bindings.

A 40MB attachment can take over 3mins to download at the frontend.

Is there a way to allow users to click on a file for background download similar to other platforms like OneDrive or GoogleDrive?

https://i.sstatic.net/gKr7v.png

My tech stack includes Vue with element UI, so any JavaScript samples would be greatly appreciated.

-- updated

Current approach:

When the user clicks "download," a $value request is initiated https://i.sstatic.net/dxVpO.jpg

and completes after approximately 1 minute.

For a complete video demonstration, check out the link.

-- code

// graphapi.js
export function getAttachment(eventId, attachmentId) {
  return request({
    url: `/events/${eventId}/attachments/${attachmentId}/$value`,
    method: 'get'
  })
}
// form.vue
// template
 <el-table-column v-if="action === 'edit'" width="150px" label="操作">
          <template slot-scope="scope">
            <el-button size="small" type="text">
              <a @click.prevent="downloadAttachment(scope.row.id)">download</a>
            </el-button>
            <el-button size="small" type="text" @click="deleteAttachment(scope.row.id)">remove</el-button>
          </template>
        </el-table-column>
// script
downloadAttachment(attachmentId) {
      const attachment = getAttachment(this.$route.params.id, attachmentId)
const link = document.createElement('a')
link.href = `data:${attachment.type};base64,${attachment.contentBytes}`
link.click()
    },

Answer №1

Storing your images on a Content Delivery Network (CDN) is essential for faster downloads and reduced server load. This ensures that files can be served to users worldwide without any delays or crashing issues.

Consider using Cloudfront or Cloudinary depending on the hosting location of your application.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can you retrieve the <head> content from a remote website without being able to make any changes to that site?

Imagine I need to access the <head> tag of a remote website like YouTube. Whenever I attempt this, I encounter an error message: Access to XMLHttpRequest at ‘Website I am trying to access for the head section’ from origin ‘My Website’ has b ...

End: unrelated, lacking responses

I have a question I'd like to discuss: Whenever I utilize the following code snippet: async function createNewElement(req,res){ const start1 = new Date().getTime(); console.log("start time 1 ", start1) await new Promise((resolve) => setT ...

Incorporating .json files into an HTML template with the help of an HTML form designed for selecting a particular

I am faced with a collection of various .json files that I wish to specify by name on an HTML page (local) form, enabling me to load this data onto a table. This is how my HTML form appears: <form> File: <input type="text" Id="file_name"&g ...

The error "Cannot access property of undefined during an Ajax POST request" indicates

I am currently facing an issue with uploading a music file using AJAX to save the data into my MongoDB when I click the 'upload' button. Unfortunately, I keep receiving an error stating that "fieldname is undefined". It seems like there might be ...

Can you explain the meaning of <!-- in javascript?

Have you ever noticed the <!-- and --> characters being used around JavaScript code like this: <script type="text/javascript"> <!-- function validateForm() { if(document.pressed == 'Submit') { ...

Replace .Mui-disabled (or any other pseudo-classes/states) in the MUI v4.1.X theme with custom styling

How can I globally override the default grey background color for disabled items in Material-UI v4.1.x? I know how to do it for specific components like MuiMenuItem, but I'd prefer a solution that doesn't require me to add overrides for each indi ...

How to Store Values from a ReadStream in an Array

I'm currently attempting to use a stream and the async/await keywords with the fast-csv library in order to read a CSV file synchronously. Unfortunately, the function I've written doesn't seem to be producing the expected output. My assumpt ...

Is it possible to utilize a single command in Discord.js to send multiple embeds?

Is there a way to create a unique bot in Node.js (using Discord.js) by utilizing Visual Studio Code? This exceptional bot should be capable of responding with various embed messages when given one specific command. I attempted using command handler, but u ...

Tips for avoiding the forward slash in a URL parameter

$.ajax({ url: "/api/v1/cases/annotations/" + case_id + "/" + encodeURIComponent(current_plink), When I use encodeURIComponent to escape slashes, it doesn't work as expected. The code converts the "slash" to "%2F", but Apache doesn't reco ...

Handling 404 Response from WebAPI in $Http.get() Function

While using my web application, I am executing a GET command to access a remote HTTP WebAPI service. $http.get(url).then(function(data) { do_something(); }); When the WebAPI successfully returns data, everything functions as expected. However, in cases w ...

Updating the selected value in TomSelect based on an ajax response

I am facing an issue setting a value on TomSelect using ajax response. Normally, I would use the following code on a general dropdown: $('#homebasepeg').val(data.hmb_id).change(); However, when I try to apply this on TomSelect, it doesn't s ...

Removing all text inside an input field with Vue

I am trying to create a password input field using type 'text' instead of 'password.' <input type="text" v-model="form.password" @input="test" /> <input type="hidden" v-model="form.hiddenPassword" /> As part of my approach ...

Trigger animation once you've scrolled past a designated point in the document

I created a count-up counter animation using JavaScript, but the issue is that the counter starts animating as soon as I refresh the page regardless of where I am on the page or if the counter is even visible. I would like the counter to only start workin ...

React.js is throwing an error due to an unexpected character '⇒'

This is my first time working with React.js and I'm experimenting with some code. I am really enjoying it, but there's one syntax error that keeps tripping me up: {this.state.data.map((person, i) ⇒ )}. An online tutorial said this should work, ...

VS code showing live server as installed but failing to function properly

After installing the live server extension, I noticed that my browser is not updating when I save my HTML or other files. What could be causing this issue? ...

Allusion to a intricate data component

In my code, I have a model that is being represented by a class. For example, let's consider the model of a car: export class Car { public name : string; public color: string; public power : number; public service : boolean; } All c ...

Experiencing an issue in Test Cafe when attempting to click on an invisible link using the Client Function

I need to find a way to click on an invisible button in HTML. I attempted to use ClientFunction, however I encountered an error related to the element. import { Selector,ClientFunction } from 'testcafe'; fixture('Clicking Invisible link&apo ...

What is the best way to transfer an array from an Express Server to an AJAX response?

My AJAX request successfully communicates with the server and receives a response that looks like this: [{name: 'example1'}, {name: 'example2'}] The issue arises when the response is passed to the client-side JavaScript code - it is t ...

Why is it that when I store a DOM element reference in a JavaScript Array, I cannot reuse that stored reference to add an event listener

I have a little confusion and I hope someone can help me out. I am facing an issue with dynamically created buttons, where each button has a unique id. To keep track of these buttons in a well-organized manner, I store their references using a simple two-d ...

Sorting custom strings in Javascript with special characters like dash (-) and underscore (_)

I am attempting to create a custom sorting method with the following order: special character ( - first, _ last) digit alphabets For instance, when sorting the array below var words = ['MBC-PEP-1', 'MBC-PEP01', 'MBC-PEP91&apo ...