Home > Software engineering >  Vb to do a folder upload function encountered a series of problems, to be solved
Vb to do a folder upload function encountered a series of problems, to be solved

Time:09-26

Arrange recently superior for a folder upload needs, first studied the Flex, learning of using FileReferance for multiple File upload, found that there is no the function of the selected folder, again to do desktop applications, find a File folder traverse the File object can select your uploads, overjoyed at that time, thought that can realize functions, the results do not understand whether can be embedded into HTML, time and tide wait for no man, or give up,
Can't, according to the instructions, and go on VB, used to do when the page is used VBS, decisive learning,
Learned a few days, baidu search, select a folder, traverse the file, the json format file generated hierarchy attribute data, studied the packaging, integrated into the JSP page, in combination with js, after selecting the page display files as well as all documents, it took a long time study inet control simulation sends the HTTP post request, baidu search, try to finally try send the request to success, receives the request, the JSP simulation using fileuploadservlet packet parsing requests, beginning has been not receive data, FileItem always empty, spent a lot of time on spelling a request data, is owing to the influence cannot receive data format problem behind the right format, this problem solved,
Read data and has a problem, so far haven't solved, I use is to read the binary mode, the open # filenum for binary read as # filenum way, according to the file size, the control of a 1 m bytes read, read cycle, cycle to send, the background code using random IO writing, speaking, reading and writing files, if it is, when reading the textstream file using the Get # filenum, and data, the data as a byte array, and then converted to string STR=StrConv (data, vbUnicode), joining together of transfer request information, the background can be normal, but if the selected file is word, PDF, rar compressed package will appear problem, such as after StrConv function transform, the character and the background, the bytes found little a lot larger than the file, upload the file always said after prompt head damage, didn't understand how to turn back to normal bytes,
Tried base64 code, generate a string, after you receive the background using the JDK provided Base64Decoder decoding, can upload files normally, but the VB to base64 encoding is slow, once read from 100 k to wait a long time, and page caton, I do not know which master myself, whether there is any better way here? But soon, the Java code decoding without a second,
Later directly through the data byte array, each byte of data, the formation of value between 0 ~ 256, Mosaic digital string, use a comma split, send back into an array of bytes written to the file, and feasible, but it happened is in the VB byte traversal spell string slowly:
For I=0 To UBound (data)
Str=Str & amp; Data (I) & amp;" , "
Next I
This code execution slowly, read 100 k also slow death,

Is now trying to the three ways, are unsatisfactory, hope expert guidance,

Three (3) problem, also a post request inet control problems, circular post request, if requested, 10 times in the middle there is 1 to 2 times the request failed, send data fragment, receives a request for icResponseCompleted inet_stateChanged method, but received no reply back the day after tomorrow, which is no request is successful,


4. Question 4, need to display the upload speed, degree of progress, need to VB code calls the Js, the echo data, how the VB callback Js function problem (O_O)?
5. Question 5, how to put js function name directly assigned to a variable of Vb? VB through this variable callback the js function??







CodePudding user response:

Properties of vb counterparts, give some instructions

CodePudding user response:

Search "robocopy"

CodePudding user response:

If necessary I can give you a design of a local upload code, uploaded to the JSP

CodePudding user response:

If not considering the transport layer technology, simple look from the HTTP protocol, can give you a HTTP packets, as long as you simulate this package connect to the server after the contract is finished,
If considering transmission technology, can choose XMLHTTP component or winsock control or socket API to build its own transport layer,
Can say simple good:
XMLHTTP components of different systems, different versions and platforms have different performance, because it is the third party components, so the basis problem sometimes can not solve, can change the version or patches, etc. If the user on the machine, then go to the maintenance, the possibility of a fatal problem is the cache, if he think you need to submit address cache, even don't use the network returns a cache the results directly to you, of course, change the url method to solve this problem, but not what version what system must be effective,

Winsock control different versions and the system performance is different also, mainly depends on the stability, and your familiarity of the winsock control, normally is normal, but by the end of the Internet, sometimes you will find that there is some accident, then you have to learn to filter the data and do n check, otherwise will certainly, still have even if you consider the HTTP transport protocol, if that needs to be perfected himself entirely, what algorithm ah, format, protocol stacks of,

Socket API compatibility is best, but much larger workload, but also a clear understanding of how to use, in addition to understand the use of more steps and models, consider to the characteristic of VB6, choose a good model to have certain efficiency and stability of the socket class is not easy, and then to do the HTTP protocol,

Relatively XMLHTTP upload the most simple, but at the same time, the minimum reliability,
Winsock control moderate, but a lot of check to filter the strange things on the Internet,
The socket API is the most complicated, but it is also the highest reliability, but relatively more workload and technical requirements,
Ok, give you a POST packet, you begin to study on their own in
 
POST/upfile. HTTP/1.1 PHP
Host: localhost
Connection: keep alive -
The Content - Length: 484
Cache-control: Max - age=0
Accept: text/HTML and application/XHTML + XML, application/XML. Q=0.9, image/webp, */*; Q=0.8
Origin: http://localhost
Upgrade - the Insecure - Requests: 1
The user-agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36
The content-type: multipart/form - data; A boundary=- WebKitFormBoundaryzNMzgpQrsNEFud2y
The Referer: http://localhost/xxx.htm
The Accept - Encoding: gzip, deflate
The Accept - Language: useful - CN, useful; Q=0.8
Cookie: PHPSESSID=h69ks340p5q5bdq9m5cefs01r9sc7grl;

-- -- -- -- -- - WebKitFormBoundaryzNMzgpQrsNEFud2y
The Content - Disposition: the form - data; Name="ucode
"
TUPrKMxV038dWinA
-- -- -- -- -- - WebKitFormBoundaryzNMzgpQrsNEFud2y
The Content - Disposition: the form - data; Name="sid"

17
-- -- -- -- -- - WebKitFormBoundaryzNMzgpQrsNEFud2y
The Content - Disposition: the form - data; Name="item"

Licence
-- -- -- -- -- - WebKitFormBoundaryzNMzgpQrsNEFud2y
The Content - Disposition: the form - data; Name="file"; Filename="test. JPG"
The content-type: image/jpeg

The MTA=
-- -- -- -- -- - WebKitFormBoundaryzNMzgpQrsNEFud2y -


Note that the
The content-type: multipart/form - data; A boundary=- WebKitFormBoundaryzNMzgpQrsNEFud2y
And each section in the middle of the
-- -- -- -- -- - WebKitFormBoundaryzNMzgpQrsNEFud2y
Is sent two "--", don't make a mistake
  • Related