Re: [twsocket] Safely save a binary file
it, but they are wrapped into headers: It is the so called MIME format which is used by browsers to send files. The question is, how to get rid of this header and footer safely. Is it enough just to delete first 4 lines and last 5 lines or it should be done some other way? You should decode it carefully. The number of header lines may vary. The last one is an empty one. Use the delimiter to find the end of data. Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be - Original Message - From: tol [EMAIL PROTECTED] To: twsocket@elists.org Sent: Friday, December 29, 2006 9:25 AM Subject: [twsocket] Safely save a binary file Hello twsocket, I'm trying to make the http server save binary files. I was able do do it, but they are wrapped into headers: -54472172614771 Content-Disposition: form-data; name=file; filename=IBM_286.rar Content-Type: application/octet-stream Rar!W+%~бяо+¤^?юLъ2¦ю--P-?+жOHOL--жP¦дC\iji¦л#Njr`mQcjo#A80 !O¤-¬є¦СББ-TБСTЙ- ipa¬ ^-ЁгїД1Й¬*жлЧЁOLЕ6aй*\¬M?¦+tHЧTbлЎч,T¬ЬLю-НL¬й№¦+ч °Э·¤)¦zO2YWR¦@ -54472172614771 Content-Disposition: form-data; name=Submit Submit -54472172614771-- The question is, how to get rid of this header and footer safely. Is it enough just to delete first 4 lines and last 5 lines or it should be done some other way? Maybe there is a function to convert this raw output to a normal file? Please advise. Thanks. -- Best regards, tol -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Safely save a binary file
Hello Francois, Friday, December 29, 2006, 1:16:14 PM, you wrote: The question is, how to get rid of this header and footer safely. Is it enough just to delete first 4 lines and last 5 lines or it should be done some other way? FP You should decode it carefully. The number of header lines may vary. The FP last one is an empty one. Use the delimiter to find the end of data. I see no obvious solution, I think there exists many ways to do it, but it should be considered that we have to deal with huge amounts of data and we need to process it fast. Suppose a user uploads a 100 megabyte file, it may take a lot of CPU and HDD time... I only could do it as follows. I tested it with 30Mb RAR archive and it was unpacked successfully after the upload. If you can suggest a better way, you are welcome. mst:=tmemorystream.create; st:=tstringstream.Create(s); st.Write(ClientCnx.FPostedDataBuffer^,clientcnx.FDataLen); delimiter:=copy(st.DataString,1, pos(#13#10,st.DataString )); fname:=copy(st.DataString,pos('filename=', st.datastring)+10, posex('',st.datastring, pos('filename=', st.datastring)+10)-(pos('filename=', st.datastring)+10)); if fname='' then fname:='unknown.file'; s1:=copy(st.DataString,pos(#13#10#13#10,st.DataString)+4, length(st.DataString)); s1:=copy(s1,1, pos(delimiter,s1)-3); st.Position:=0; st.Size:=0; st.writeString(s1); mst.LoadFromStream(st); mst.SaveToFile('c:\'+fname); st.Free; mst.Free; -- Best regards, tol -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be