Read with WEB Core Delphi stream file

What is the easiest way to read a file written with Delphi Streamfile with Webcore.

Delphi Code:
Stream := TFileStream.Create(DataDir + 'data\data1.str', fmCreate);
len := SizeOf(Recordx);
Stream.WriteBuffer(len,8); // write len Record
Stream.WriteBuffer(Projekt.Dp, len); // write Record
Stream.Free;

WebCore Code -- but not possible
Stream := TBytesStream.Create;
Stream.LoadFromFile('data\data1.str');
Stream.Read(len,8);
Stream.Read(Recordx,len);
Stream.Free;

Have you tried a TMemoryStream?
If you load the file (if this is a local file, you need a file picker for this), you can assign the TJSArrayBuffer retrieved from the file picker to TMemoryStream.Memory and then read from it.

The file is on the server.

until now i'm doing that by converting to string and then reading into WebMemo.

WebMemo.Lines.LoadFromFile ('data \ webhmi.ini');

But I have to change everything back again, which doesn't necessarily make sense.

With a stream, I could read the entire record at once without conversion.

At stream level, there is at this moment not a LoadFromFile() method.
You could get the file contents using a TWebHttpRequest.
It is an interesting suggestion to have a LoadFromFile() and we've added this on the list for consideration.

this has already been solved
I need to interpret a serial file that is on a server.

something like "LoadFromFileToByteArray()" or "SaveToFileFromByteArray()"

If you use TWebHttpRequest, set ResponseType to rtArrayBuffer and then perform a GET request.
Then, in the OnRequestResponse event handler, you should be able to cast the ARequest.req.response to a TJSArrayBuffer and use this data returned.

Thanks for the tip: works fine

now I have a new problem.

What do I have to do to have only the "index.html" and maybe the "xxx.js" file in the route and all other files generated by TMS in a subdirectory?

Reason:
The hardware on which the web server runs has div. directories. One of them was "webhmi" and under this directory the whole TMS web project was deployed. The webserver was also set to this directory. So the "index.html" was started from the "webhmi" directory.

X:/data
X:/sys
X:/webhmi/ tms.js
           index.html
           webForm_01.html
           webForm_01.pa_Background.ic_WoProg.Picture.png
            ...
           webForm_02.html
           webForm_02.pa_Right.im_btPgUp.Picture.png
            ...

Now it has a file in the directory "data "which I should read with this TWebHttpRequest.
But this only works if the webserver-path points directly to the route-directory, so I can access all directories.
Now the access works.
But now I have the problem that all files generated by TMS are in this route , which is not nice.

X:/data
X:/sys
X:/tms.js
   index.html
   webForm_01.html
   webForm_01.pa_Background.ic_WoProg.Picture.png
    ...
   webForm_02.html
   webForm_02.pa_Right.im_btPgUp.Picture.png
    ...

Can I put these files back into the webhmi directory except the "index file" ?
And where can I set the path in the JS for the generated files from TMS.

all files I load myself at runtime I could put back into the "webhmi" directory where I added the access with "\webhmi", but I can't do that with the files generated by TMS.

It is assumed that all form .HTML files are in the same folder as these HTML files are loaded by the framework with relative filenames. So, the root project HTML file (index.html) and the form HTML files are assumed to be in the same folder.
If you need to access a file in a folder data above this app subfolder, you should be able to access that with an absolute server path URL.

how do i specify the absolute server path URL?
this does not work

GET http://192.168.200.67/data/error2.his
[HTTP/1.1 404 Not Found 14ms]
	
GET http://192.168.200.67/data/error2.his
Status 404 Not Found
Version HTTP/1.1
Übertragen 226 B (156 B Größe)
Referrer Policystrict-origin-when-cross-origin

my structure looks like this:

root://data/error1.his
root://data/error2.his

root://webhmi/index.html
root://webhmi/xxx.js
root://webhmi/ ...........

WebServer path set to webhmi so that all web files are under webhmi

I can't read the files under data.
My attempts look like this:

http://192.168.200.67/data/error1.his
192.168.200.67/data/error1.his
http:\\192.168.200.67\data\error1.his
192.168.200.67\data\error1.his

the same with error files in root

http:\\192.168.200.67\error1.his
192.168.200.67\error1.his
....

once i have the files under root://webhmi i can read them.

error1.his

that's all it takes

What exactly do I have to do that the access to data works.
In my opinion this does not work at all, because I have the root of the webserver on root://webhmi, or?

i can't go back on the path tree than the "webserver root"
in my case
root://webhmi

Can't the browser access
http://192.168.200.67/data/error1.his ?

If the browser itself cannot access this, I can only suspect there is a config issue on your webserver that it doesn't make this file accessible.

Delphi

  whtRequest.URL      := 'http://192.168.200.67/data/error1.his';
  whtRequest.Execute;
.

js

     this.whtRequest.FURL = "http:\/\/192.168.200.67\/data\/error1.his";
     this.whtRequest.Execute(null);

firefox


GET http://192.168.200.67/data/error1.his 
[HTTP/1.1 404 Not Found 8ms]
  • List item

If you get a 404, the web server doesn't offer access to the file, so it is a web server config issue.

If I change the web server root directory from root://webhmi
to root:// can access root://data ...

but then I have all webfiles in the root:// which I don't want this

until now I have found no settings where I can change this
I can only set the web server root path

In that case this is a server config issue. If you will want to the web app to access the files under data, the files should be made accessible in the web server config.