CN107426331A - A kind of file uploading method and device based on JavaScript - Google Patents

A kind of file uploading method and device based on JavaScript Download PDF

Info

Publication number
CN107426331A
CN107426331A CN201710674572.1A CN201710674572A CN107426331A CN 107426331 A CN107426331 A CN 107426331A CN 201710674572 A CN201710674572 A CN 201710674572A CN 107426331 A CN107426331 A CN 107426331A
Authority
CN
China
Prior art keywords
file
piecemeal
javascript
browser
mrow
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201710674572.1A
Other languages
Chinese (zh)
Inventor
张乃文
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Tianxin Ruian Information Technology Co Ltd
Original Assignee
Beijing Tianxin Ruian Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Tianxin Ruian Information Technology Co Ltd filed Critical Beijing Tianxin Ruian Information Technology Co Ltd
Priority to CN201710674572.1A priority Critical patent/CN107426331A/en
Publication of CN107426331A publication Critical patent/CN107426331A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/06Protocols specially adapted for file transfer, e.g. file transfer protocol [FTP]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • G06F16/137Hash-based
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/14Details of searching files based on file metadata
    • G06F16/148File search processing
    • G06F16/152File search processing using file content signatures, e.g. hash values

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Library & Information Science (AREA)
  • Storage Device Security (AREA)

Abstract

The present invention discloses a kind of file uploading method based on JavaScript, comprises the following steps:Selection needs the file uploaded;Piecemeal is carried out to file by JavaScript;Calculate and preserve file fingerprint.Wherein, method of partition can meet to perform many requirements such as speed, information viewpoint, memory consumption, stability, the file of each upload in need, operation program, calculate most suitable piecemeal size automatically, and implement piecemeal;Computational methods are using hash algorithm serial SHA x, compromise between security and stability.The present invention teaches skill art based on the browser second and implemented, it is necessary to which file server and Web page coordinate, when user uses transmitting file on browser, if before file on be transmitted through, without upload again, upload is completed at once, the time of upper transmitting file in browser is saved, saves broadband.

Description

A kind of file uploading method and device based on JavaScript
Technical field
The present invention relates to field of computer technology, and in particular to a kind of file uploading method and dress based on JavaScript Put.
Background technology
Transmitting file is conventional function from browser, mainly there is three kinds of implementations at present:1. based on the upper of Flash Pass;2. the upload based on browser form;3. the upload based on stream.Above-mentioned three kinds of implementations are all needed in file content whole Pass to server.It is existing to be based on client file and " second biography " is the mode that uploads a kind of common in Dropbox " ignoring formula " A kind of optimization method uploaded, its principle are:If file exists on the server, complete text just can not be uploaded again Part content.
The client-based second, which passes, to be needed to download particular clients, in-convenience in use.Taught skill on file based on browser Art always needs to upload complete file content, many times has and wastes flow, wastes broadband, when increasing user time wait Between the shortcomings that.
In view of drawbacks described above, creator of the present invention obtains the present invention finally by prolonged research and practice.
The content of the invention
To solve above-mentioned technological deficiency, the technical solution adopted by the present invention is, there is provided a kind of based on JavaScript's File uploading method, its step are:
Step S1, selection need the file uploaded;
Step S2, piecemeal is carried out to file by JavaScript;
Step S3, calculate and preserve file fingerprint;
Step S4, fingerprint is sent to server and verified.
Preferably, method of partition is in the step S2:
Wherein,
A represents that the size of transmitting file, unit Gb need to be gone up;
B represents piecemeal size, unit Gb;
C represents piecemeal number, c > 0, and c is integer;
K is additional amount, unit Gb.
Preferably, the step S4 is specially:If the verification passes, step S4-1 is performed, if checking is not by performing Step S4-2:
Step S4-1 directly replicates from server
Can directly it be replicated from server, the content without the upper transmitting file from browser;
Step S4-2 transmitting files from browser
The content of upper transmitting file from browser.
Preferably, using the hash algorithm of SHA-x series in the step 3.
Preferably, SHA-1 algorithms are used in the step 3.
Preferably, SHA-256 algorithms are used in the step 3.
The present invention also provides a kind of file based on JavaScript and uploads device, and it includes:
Uploading unit:For selecting and upper transmitting file;
Blocking unit:Piecemeal is carried out to the file by JavaScript;
Computing unit:For calculating and preserving file fingerprint;
Authentication unit:For verifying the fingerprint.
Compared with the prior art the beneficial effects of the present invention are:
1, the present invention teaches skill art, it is necessary to which file server and Web page coordinate based on the browser second, and user uses browser During upper transmitting file, if before file on be transmitted through, without uploading again, upload is completed at once, is saved in browser The time of transmitting file, save broadband.This method can quickly calculate most suitable piecemeal size, abundant satisfaction execution speed, Many requirements such as information viewpoint, memory consumption, stability, the file of each upload in need, operation program are automatic to calculate Go out most suitable piecemeal size, and implement piecemeal.
2, the present invention also supports directly to upload catalogue in browser, if the file of identical content, phase under User Catalog Same part only needs to take a broadband.
3, the present invention uses newest JavaScript technologies, and the file that high intensity is efficiently calculated in browser refers to Line, it can accomplish at present or so 100MB/ seconds, such 100MB file can upload to service end, browser clients in 1 second The network broadband of very little is only needed to be used to send message between end and server.
4, using the hash algorithm of SHA-x series, there is higher security than traditional MD5 algorithms.Collision probability is small, Different files are effectively avoided identical hash situation occur, being capable of compromise between security and speed both sides standard.
Brief description of the drawings
It is required in being described below to embodiment in order to illustrate more clearly of the technical scheme in various embodiments of the present invention The accompanying drawing used is briefly described.
Fig. 1 is the flow chart of the inventive method;
Fig. 2 is the system block diagram of apparatus of the present invention.
Embodiment
Below in conjunction with accompanying drawing, the forgoing and additional technical features and advantages are described in more detail.
Embodiment 1
The present invention provides a kind of file uploading method based on JavaScript, the implementation passed based on the browser second, it is necessary to File server and Web page coordinate.User is using during transmitting file, file can be pressed fixed size by file server on browser Piecemeal is carried out, calculates and preserves the file fingerprint of each piecemeal.If before file on be transmitted through, without upload again, Upload is completed at once, can save the time of transmitting file on browser, saves broadband.
As shown in figure 1, it is a kind of flow chart of JavaScript file uploading file of the present invention, of the invention is specific Implementation steps are as follows:
Step S1 selections need the file uploaded
User opens in browser uploads the page, and the file for needing to upload is chosen in corresponding document underedge, and clicks on Pass.
Step S2 carries out piecemeal by JavaScript to file
The file that uploads is needed when choosing, and after clicking on upload, browser page uses JavaScriptFileReader reads file content according to server identical piecemeal.The core concept of piecemeal is:With Exemplified by 100Mb sizes, the carry out piecemeal more than 100Mb, otherwise monoblock reading.For the file more than 100Mb, and with 100Mb Split for unit, guarantee is uploaded with the size no more than 100Mb every time.For example 304Mb file can be divided into Tetra- pieces of 100Mb, 100Mb, 100Mb, 4Mb is successively read.
In the practical application that file uploads, the size of file block directly affects the speed and efficiency of file upload, The too small information viewpoint that can influence server storage of file block, file block too conference cause stability degradation, internal memory Consumption becomes big and even overflowed, and calculated in step S3 file fingerprint time it is elongated, or even trigger browser collapse.It can be seen that The importance that suitable file block size uploads to file is chosen, creator of the present invention passes through prolonged research and time, It was found that when piecemeal size and file size have following relation, it can fully meet that performing speed, information viewpoint, internal memory disappears Many requirements such as consumption, stability:
Wherein,
A represents that the size of transmitting file, unit Gb need to be gone up;
B represents piecemeal size, unit Gb;
C represents piecemeal number, c > 0, and c is integer.
If file is too big, it can be worked to piecemeal and bring great inconvenience, influenceed processor treatment effeciency, be incorporated herein additional K is measured, unit Gb, user can be set according to being actually needed, to reach more preferable piecemeal effect.
By above-mentioned formula, most suitable piecemeal size can be quickly calculated, without largely being tested, point Its speed data is not recorded.Above-mentioned formula uses simply, quickly, is written as JavaScript code, so, every time The file of upload in need, operation program, most suitable piecemeal size is calculated automatically, and implement piecemeal.
Step S3 is calculated and is preserved file fingerprint
Browser and service end identical block algorithm, to each section technique file fingerprint, have been stored afterwards Come.
When each section technique file fingerprint is corresponded in browser, the JavaScript generations of optimization are write using asm.js Code, this code execution speed is faster than in general JavaScript, can accomplish 1/3 to 1/2 performance of identical C code, With the fireballing advantage of execution.
Herein from the good algorithm of security, the hash algorithm of prioritizing selection SHA-x series, collision probability is small, as far as possible Different files are avoided identical hash situation occur, being capable of compromise between security and speed both sides standard.The choosing of hash algorithm Final execution efficiency can also be influenceed by selecting, and can be weighed according to the needs of safety and performance and selected, such as:SHA-1 is current still Comparatively safe and performance acceptable algorithm, SHA-256 securities are also fine, but speed can be slow several times.And MD5 etc Although algorithm is simple efficiently, have proven to unsafe, it is not recommended that use.
In order to avoid the execution efficiency of JavaScript code influences the performance of the page, the present invention uses optimization JavaScript code, some optimisation strategies are employed in compiling procedure, to improve treatment effeciency.
Fingerprint is dealt into server and verified by step S4
File fingerprint is dealt into server to be verified, if the verification passes, then documentary evidence has been present, and performs step S4-1, if checking is not by performing step S4-2.
Step S4-1 directly replicates from server
Can directly it be replicated from server, the content without the upper transmitting file from browser.
Step S4-2 transmitting files from browser
The content of upper transmitting file from browser.
Embodiment 2
Based on same inventive concept, the present invention also provides a kind of file based on JavaScript and uploads device, such as Fig. 2 institutes Show, it is the system block diagram of apparatus of the present invention.The upload device includes:Uploading unit 1, blocking unit 2, computing unit 3, test Demonstrate,prove unit 4.
The uploading unit 1 is used for selecting to need the file uploaded.User opens upload interface in a browser, corresponding File in choose and need the file that uploads, and click on upload.
The blocking unit 2 carries out piecemeal by JavaScript to the file of upload.Use JavaScriptFileReader piecemeals read file content, and the core concept of piecemeal is:By taking 100Mb sizes as an example, it is more than 100Mb carry out piecemeal, otherwise monoblock reading.
It is of crucial importance to file uploading operation to choose suitable file block size, piecemeal is excessive or too small can all cause Transfer efficiency reduces, and the blocking unit 2 uses following method of partition:
Wherein,
A represents that the size of transmitting file, unit Gb need to be gone up;
B represents piecemeal size, unit Gb;
C represents piecemeal number, c > 0, and c is integer.
If file is too big, it can be worked to piecemeal and bring great inconvenience, influenceed processor treatment effeciency, be incorporated herein additional K is measured, unit Gb, user can be set according to being actually needed, to reach more preferable piecemeal effect.
By above-mentioned computational methods, most suitable piecemeal size can be quickly calculated, without largely being surveyed Examination, records its speed data and is compared successively respectively.The piecemeal size calculated, it can fully meet to perform speed, letter Cease many requirements such as angle, memory consumption, stability.Above-mentioned formula uses simple, quick, is written as JavaScript code, so, the file of each upload in need, operation program, most suitable piecemeal size is calculated automatically, And implement piecemeal.
The computing unit 3 is used for calculating and preserving file fingerprint, and browser and service end use identical block algorithm.
When corresponding to each section technique file fingerprint in a browser, the JavaScript generations of optimization are write using asm.js Code, this code execution speed is faster than in general JavaScript, can accomplish 1/3 to 1/2 performance of identical C code, With the fireballing advantage of execution.
It is preferred that from the hash algorithm of SHA-x series, collision probability is small, can effectively avoid different files from occurring identical Standard of both hash situation, compromise between security and speed.The selection of hash algorithm can also influence final execution efficiency, It can be weighed according to the needs of safety and performance and selected, such as:SHA-1 is current or comparatively safe and performance acceptable is calculated Method, Sha-256 securities are also fine, but speed can be slow several times.And although MD5 etc algorithms are simple efficiently, by It is proved to be unsafe, it is not recommended that use.
In order to avoid the execution efficiency of JavaScript code influences the performance of the page, the computing unit 3 uses optimization JavaScript code, some optimisation strategies are used in compiling procedure, to improve treatment effeciency.
The authentication unit 4 is used for file fingerprint being sent on server, and is verified.If the verification passes, then Documentary evidence has been present, and can directly be replicated from server, the content without the upper transmitting file from browser;If checking Not by the content of upper transmitting file from browser.
Presently preferred embodiments of the present invention is the foregoing is only, is merely illustrative for the purpose of the present invention, and it is non-limiting 's.Those skilled in the art understands, many changes can be carried out to it in the spirit and scope that the claims in the present invention are limited, Modification, in addition it is equivalent, but fall within protection scope of the present invention.

Claims (7)

1. a kind of file uploading method based on JavaScript, is comprised the following steps that:
Step S1, selection need the file uploaded;
Step S2, piecemeal is carried out to the file by JavaScript;
Step S3, calculate and preserve file fingerprint;
Step S4, the fingerprint is sent to server and verified.
It is 2. as claimed in claim 1, it is characterised in that method of partition is in the step S2:
<mfenced open = "{" close = ""> <mtable> <mtr> <mtd> <mi>b</mi> <mo>=</mo> <mfrac> <mrow> <mi>a</mi> <mo>+</mo> <mn>1</mn> </mrow> <mrow> <mi>c</mi> <mo>+</mo> <mn>2</mn> </mrow> </mfrac> <mo>,</mo> <mo>(</mo> <mn>0</mn> <mo>&lt;</mo> <mi>a</mi> <mo>&lt;</mo> <mn>1</mn> <mo>)</mo> </mtd> </mtr> <mtr> <mtd> <mi>b</mi> <mo>=</mo> <mfrac> <mrow> <mi>a</mi> <mo>+</mo> <mi>k</mi> <mo>+</mo> <mn>1</mn> </mrow> <mrow> <mi>c</mi> <mo>+</mo> <mn>4</mn> </mrow> </mfrac> <mo>,</mo> <mo>(</mo> <mi>a</mi> <mo>&amp;GreaterEqual;</mo> <mn>1</mn> <mo>)</mo> </mtd> </mtr> </mtable> </mfenced>
Wherein,
A represents that the size of the file, unit Gb need to be uploaded;
B represents piecemeal size, unit Gb;
C represents piecemeal number, c > 0, and c is integer;
K is additional amount, unit Gb.
It is 3. as claimed in claim 2, it is characterised in that the step S4 is specially:If the verification passes, step S4- is performed 1, if checking is not by performing step S4-2:
Step S4-1 directly replicates from server;
Step S4-2 transmitting files from browser.
4. as described in claim any one of 1-3, it is characterised in that calculated in the step 3 using the Hash of SHA-x series Method.
It is 5. as claimed in claim 4, it is characterised in that SHA-1 algorithms are used in the step 3.
It is 6. as claimed in claim 4, it is characterised in that SHA-256 algorithms are used in the step 3.
7. a kind of file based on JavaScript uploads device, it is characterised in that including:
Uploading unit:For selecting and upper transmitting file;
Blocking unit:Piecemeal is carried out to the file by JavaScript;
Computing unit:For calculating and preserving file fingerprint;
Authentication unit:For verifying the fingerprint.
CN201710674572.1A 2017-08-09 2017-08-09 A kind of file uploading method and device based on JavaScript Pending CN107426331A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710674572.1A CN107426331A (en) 2017-08-09 2017-08-09 A kind of file uploading method and device based on JavaScript

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710674572.1A CN107426331A (en) 2017-08-09 2017-08-09 A kind of file uploading method and device based on JavaScript

Publications (1)

Publication Number Publication Date
CN107426331A true CN107426331A (en) 2017-12-01

Family

ID=60436778

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710674572.1A Pending CN107426331A (en) 2017-08-09 2017-08-09 A kind of file uploading method and device based on JavaScript

Country Status (1)

Country Link
CN (1) CN107426331A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108881461A (en) * 2018-07-02 2018-11-23 深圳市茁壮网络股份有限公司 A kind of data transmission method, apparatus and system
CN111586094A (en) * 2020-03-26 2020-08-25 平安养老保险股份有限公司 File uploading method and device and computer equipment
US11184423B2 (en) 2018-10-24 2021-11-23 Microsoft Technology Licensing, Llc Offloading upload processing of a file in a distributed system using a key that includes a hash created using attribute(s) of a requestor and/or the file

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101699822A (en) * 2009-08-06 2010-04-28 腾讯科技(深圳)有限公司 File uploading method and device, and mass storage system
US20140279846A1 (en) * 2013-03-13 2014-09-18 CoralTree Inc. System and method for file sharing and updating
CN104247376A (en) * 2013-04-02 2014-12-24 华为技术有限公司 File uploading method in cloud storage, client, application server, and cloud storage system
CN104639629A (en) * 2015-01-30 2015-05-20 英华达(上海)科技有限公司 File comparing method and system at client and cloud

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101699822A (en) * 2009-08-06 2010-04-28 腾讯科技(深圳)有限公司 File uploading method and device, and mass storage system
US20140279846A1 (en) * 2013-03-13 2014-09-18 CoralTree Inc. System and method for file sharing and updating
CN104247376A (en) * 2013-04-02 2014-12-24 华为技术有限公司 File uploading method in cloud storage, client, application server, and cloud storage system
CN104639629A (en) * 2015-01-30 2015-05-20 英华达(上海)科技有限公司 File comparing method and system at client and cloud

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108881461A (en) * 2018-07-02 2018-11-23 深圳市茁壮网络股份有限公司 A kind of data transmission method, apparatus and system
US11184423B2 (en) 2018-10-24 2021-11-23 Microsoft Technology Licensing, Llc Offloading upload processing of a file in a distributed system using a key that includes a hash created using attribute(s) of a requestor and/or the file
CN111586094A (en) * 2020-03-26 2020-08-25 平安养老保险股份有限公司 File uploading method and device and computer equipment

Similar Documents

Publication Publication Date Title
WO2021008113A1 (en) Data evidence storage method, data verification method and related apparatuses based on blockchain
CN104410692B (en) A kind of method and system uploaded for duplicate file
Cui et al. QuickSync: Improving synchronization efficiency for mobile cloud storage services
CN103095843B (en) A kind of data back up method and client based on version vector
US8612594B1 (en) Systems and methods for preventing data loss from files sent from endpoints
US11088828B2 (en) Blockchain-based data evidence storage method and apparatus
US9811676B1 (en) Systems and methods for securely providing information external to documents
CN105635324A (en) Big file uploading and continuous uploading method and device for browser or server
CN103116615B (en) A kind of data index method and server based on version vector
CN106021256A (en) De-duplicating distributed file system using cloud-based object store
US20110113466A1 (en) Systems and Methods for Processing and Managing Object-Related Data for use by a Plurality of Applications
CN107426331A (en) A kind of file uploading method and device based on JavaScript
CN103118104B (en) A kind of data restoration method and server based on version vector
US20190253436A1 (en) Method, system, and apparatus for monitoring network traffic and generating summary
CN104468843A (en) File uploading method and device
CN103944988A (en) Repeating data deleting system and method applicable to cloud storage
TW201423426A (en) System and method for diving document into data parts and uploading the data parts
WO2017215646A1 (en) Data transmission method and apparatus
CN107451467A (en) A kind of weak passwurd check method and device
CN110493302A (en) A kind of document transmission method, equipment and computer readable storage medium
CN103699610A (en) Method for generating file verification information, file verifying method and file verifying equipment
Chang et al. Cloud computing storage backup and recovery strategy based on secure IoT and spark
CN107819748A (en) A kind of anti-identifying code implementation method cracked and device
CN104023070A (en) File compression method based on cloud storage
CN108563396B (en) Safe cloud object storage method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20171201

RJ01 Rejection of invention patent application after publication