Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Update to retrieve all presigned urls in one network call, instead of having to make a call for each and every uploaded part. #6

Open
NguyenAndrew opened this issue Mar 12, 2020 · 0 comments

Comments

@NguyenAndrew
Copy link

NguyenAndrew commented Mar 12, 2020

Thank you for this example repo for frontend multipart presigned url uploads.

I noticed a change that will help improve performance, and will help anyone taking this approach! This issue has been made to get this improvement implemented.

Context

The current frontend code does something like this

for (let index = 1; index < NUM_CHUNKS + 1; index++) {
    start = (index - 1)*FILE_CHUNK_SIZE
    end = (index)*FILE_CHUNK_SIZE
    blob = (index < NUM_CHUNKS) ? this.state.selectedFile.slice(start, end) : this.state.selectedFile.slice(start)

    // (1) Generate presigned URL for each part
    let getUploadUrlResp = await axios.get(`${this.state.backendUrl}/get-upload-url`, {
        params: {
            fileName: this.state.fileName,
            partNumber: index,
            uploadId: this.state.uploadId
        }
     })
    ...
}
...

This previous code creates a growing network cost. Larger files will have more NUM_CHUNKS (parts) then smaller files, so this call will be made more times for larger files (compared to smaller files).

However, even though larger files will normally take longer to upload anyway, this cost in particular can be avoided! An example of this improvement is shown below:

let getUploadUrlResp = await axios.get(`${this.state.backendUrl}/get-upload-urls`, {
    params: {
        fileName: this.state.fileName,
        numberOfParts: NUM_CHUNKS
        uploadId: this.state.uploadId
    }
});

for (let index = 1; index < NUM_CHUNKS + 1; index++) {
    ...
}
...

This change converts /get-upload-url being called NUM_CHUNKS times, to /get-upload-urls being called a single time (no matter the file size!).

As part of fixing this issue, the following should be done:

@NguyenAndrew NguyenAndrew changed the title Update to retrieve all presigned urls in one network call, instead of having to make a call for each and every uploaded part. Improvement: Update to retrieve all presigned urls in one network call, instead of having to make a call for each and every uploaded part. Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant