Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of multipart upload and breakpoint continuation of javascript

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "javascript fragment upload, breakpoint continuation method". In the daily operation, I believe that many people have doubts about the method of javascript fragment upload and breakpoint continuation. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "javascript fragment upload, breakpoint continuation method". Next, please follow the editor to study!

Principle: file upload is to cut the file into small pieces, and then upload them one by one

Backend convention API:

1.getRestChunkInfo gets the upload status of the current file.

Enter: {fileName, fileSize, md5, token}

Output: {chunk_list, chunk_size, chunk_count}

Chunk_list is an array of information such as the number of unuploaded blocks

Chunk_size: the size of the part

Chunk_count: the total number of shards

2.uploadAPI

Enter: FormData object, specific information of the block

{file_name, file_size, file_md5, token}

Output: an object containing true/false

Steps:

1. Get the file to be uploaded, and use the md5 algorithm to do the message summary, that is, the md5 code is used as the unique ID of the file.

two。 Pass the md5 code, file name, file size and token value as input parameters to the first API in the background

3. The API returns parameters such as chunk_list, and uses chunk_list.shift to take parts and continue to call the second API to upload file blocks one by one.

4. After all files are uploaded, in order to prevent the parts with errors, the first API is requested this time. If the length of chunk_list is 0, it means that all parts are uploaded successfully.

After completing the above steps, the backend can merge files after confirming that all multipart uploads are complete.

Illustration:

The value of token is not a required parameter, but only for security reasons in order to prevent CSRF attacks. Note: security considerations and the ability to add signatures and verify signatures

Difficulties:

1. How to slice, using the slice method blob.slice (startByte,endByte) of the Blob object

two。 The number of uploaded pieces of the current file, and then make sure which one I start uploading.

At this point, the study of "javascript fragment upload, breakpoint continuation method" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report