elGringo Posted April 11, 2018 Share Posted April 11, 2018 hi, looks like simple task, but cannot understand what am i doing wrong having <a href="UploadFolder/TestFile.txt">TestFile.txt</a> on Server doing procedure TUniServerModule.UniGUIServerModuleHTTPCommand(ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var Handled: Boolean); var uriWinSlash: string; filepath: string; ext: string; begin // ext := ExtractFileExt(ARequestInfo.URI); if ext <> '' then begin uriWinSlash := StringReplace(ARequestInfo.URI, '//', '', [rfReplaceAll]); uriWinSlash := StringReplace(uriWinSlash, '/', '\', [rfReplaceAll]); if uriWinSlash[1] = '\' then uriWinSlash := uriWinSlash.Substring(1); filepath := UniServerModule.StartPath + uriWinSlash; // AResponseInfo.ServeFile(AContext, filepath); UniSession.SendFile(filepath); // << here mistake // Handled := true; end; end; but having mistakes in work of Server if even not downloading... What's up? Any other ideas how to download file from HTML code? Quote Link to comment Share on other sites More sharing options...
elGringo Posted April 11, 2018 Author Share Posted April 11, 2018 On simple HTTP Server i'am doing smth like this in OnCommandGet begin URIDecoded := TNetEncoding.URL.Decode(ARequestInfo.URI); IsWebPage := false; if IsFileOnServerByURI(URIDecoded, filepath, IsWebPage, WebPageContent) then begin AResponseInfo.ResponseNo := 200; if IsWebPage then AResponseInfo.ContentText := WebPageContent else AResponseInfo.ServeFile(AContext, filepath); end else AresponseInfo.ResponseNo := 404; end; But in UniGUI there is no AContext param... Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted April 11, 2018 Share Posted April 11, 2018 Is your upload folder a subfolder of UniGUI root folder? Then you have nothing to do in HTTPCommand... Quote Link to comment Share on other sites More sharing options...
elGringo Posted April 11, 2018 Author Share Posted April 11, 2018 ok, Progress, i can do like this in HTML <html> <a href="http://www.google.com" onclick="return myFunction();">Link</a> <script> function myFunction() { document.getElementById(".myDiv").style.flexGrow = "5"; } </script> </html> next step is to learn to request through ajaxRequest from free HTML - is that possible? Quote Link to comment Share on other sites More sharing options...
elGringo Posted April 11, 2018 Author Share Posted April 11, 2018 Is your upload folder a subfolder of UniGUI root folder? Then you have nothing to do in HTTPCommand... Yes, file in root/UploadFolder What you suggest? Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted April 11, 2018 Share Posted April 11, 2018 Link should work without to do something. Quote Link to comment Share on other sites More sharing options...
elGringo Posted April 11, 2018 Author Share Posted April 11, 2018 ok, my decision of my problem is <html> <a href="#" onclick="return myFunction();">Link</a> <script> function myFunction() { alert('here'); ajaxRequest(MainForm.window, 'getFile', [ 'filePath=12345', 'param1=B' ]); } </script> </html> and on Server Side if SameText(EventName, 'getFile') then begin showmessage(Params.Values['filePath']); end; Quote Link to comment Share on other sites More sharing options...
elGringo Posted April 12, 2018 Author Share Posted April 12, 2018 the only problem is i have js exception (see picture) my temporary decision is using timer - but it is not Ok decision ! html := '<a href="#" onclick="return myFunction();">' + f.qFiles.FieldByName('fileName').AsString + '</a>' + // '<script>' + // 'function myFunction() {' + // 'replaceThis; ' + // <<<<<<<<<<<<<<<< !!! Here // 'ajaxRequest(MainForm.window, ''getFile'', [ ''filePath=12345'', ''param1=B'']);' + // 'return;' + // '}' + // '</script>'; FFilePath := f.qFiles.FieldByName('filePath').AsString; UniSession.AddJS(UniHTMLMemo.JSName + '.execCmd(''InsertHTML'',''' + html + ''')'); tReplace.Enabled := true; and on timer tReplace.Tag := tReplace.Tag + 1; // inc(tReplace.Tag); if tReplace.Tag = 2 then begin UniHTMLMemo.Text := StringReplace(UniHTMLMemo.Text, 'replaceThis', 'ajaxRequest(MainForm.window, ''getFile'', [ ''filePath=' + FFilePath + ''', ''param1=B'']);', [rfReplaceAll]); tReplace.Enabled := false; end; What could be the problem? You can easily reproduce the case by placing UniHTMLMemo and applying this code from previous message. Quote Link to comment Share on other sites More sharing options...
Ron Posted April 12, 2018 Share Posted April 12, 2018 Are you trying to download a file? See attached project. download.zip Quote Link to comment Share on other sites More sharing options...
elGringo Posted April 13, 2018 Author Share Posted April 13, 2018 Thank you delphiDude !!! I will watch your example. below - decision from DD procedure TMainForm.bTestClick(Sender: TObject); var html: string; begin html := '<a href="#" onclick="return myFunction();">Click Me</a>' + // '<script>' + // 'function myFunction() {' + // // 'replaceThis; ' + // 'ajaxRequest(MainForm.window, "getFile", [ "filePath=12345", "param1=B"]);' + // 'return;' + // '}' + // '</script>'; // FFilePath := f.qFiles.FieldByName('filePath').AsString; UniSession.AddJS(UniHTMLMemo.JSName + '.execCmd(''InsertHTML'',''' + html + ''')'); end; please try to use " instead of ' and ' Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.