Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: different video download with same url



Permlink Replies: 11 - Last Post: Mar 17, 2016 12:31 AM Last Post By: Alexandre Machado
Adalbert Menhofer

Posts: 10
Registered: 4/10/03
different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 8, 2016 11:36 AM
I want to embed videos:

<video id="my_video" width="480" height="320" controls="controls">
<source src="/sess_files/product.mp4" type="video/mp4">
</video>

the problem is, that "product.mp4" is not a static file, but depending on some conditions I have to offer a specific file out of some hundreds.
because of the requirement I can't change the line in the html-code; it must be static '... src="/sess_files/product.mp4" ...'

For other files, I patched the IW.Server.HttpIndy, but for this I need the UserSession and beside Forms and Callback I don't know, how I can catch a request in the MainForm and set the Response dynamic for a Html-Request 'src="/sess_files/product.mp4"',
can't use Ajax-callbacks with data, because the video-files can be very big.
please can you help me ?
Adalbert Menhofer

Posts: 10
Registered: 4/10/03
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 8, 2016 1:06 PM   in response to: Adalbert Menhofer in response to: Adalbert Menhofer
I forgot: also for security reason it's not possible to simply provide al Folder /wwwroot/Videos
that contain calculations, that only specific users may read.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 8, 2016 2:45 PM   in response to: Adalbert Menhofer in response to: Adalbert Menhofer
If you are trying to dynamically deliver video content on a form, you can use a label, and the OnRender event.

1. Put a label on your form and set it's RawText to true;
2. In the form's OnRender event implement your logic to deliver the content by setting the label's caption.

procedure TIWForm1.IWAppFormRender(Sender: TObject);
begin
  with UserSession do
  begin
     if (Customer.IsSubscriber) then
     begin
        MyVideoLabel.Caption := '<video id="my_video" width="480" height="320" controls="controls">'
                                               +'<source src="/sess_files/product.mp4" type="video/mp4">'
                                               +'</video>';
     end
     else
     begin
        MyVideoLabel.Caption := '<video id="my_video" width="480" height="320" controls="controls">'
                                               +'<source src="/sess_files/overview.mp4" type="video/mp4">'
                                               +'</video>';
 
 
     end;
  end;
end;


You could also use the same solution in the OnCreate event. You could also add a method to the form that could be called from events on other forms. This technique works with any type of HTML element.
Adalbert Menhofer

Posts: 10
Registered: 4/10/03
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 9, 2016 9:19 AM   in response to: Daniel Fields in response to: Daniel Fields
Daniel, thak you very much for your investigations, but that is not the problem.

It's inpossible to have fixed files like
... src="/sess_files/product.mp4"
and
... src="/sess_files/overview.mp4"

It's the same Problem as if you want to get the files from a database depending on some conditions of the usercontext, but in html you have fixed
... src="/sess_files/product.mp4"

So please simple imagine, you would like to generate a video dynamically in a stream and embed some informations - there is no real file.

But I found a way to a solution:

<source src="/nZKZmKrdqJq1rJeYndLgmKeWqZG1ndzbrueWquuZmdC/$/callback?callback=my_video_routine&id=product.mp4" ...

(the substring "/nZKZmKrdqJq1rJeYndLgmKeWqZG1ndzbrueWquuZmdC/$" can be replaced by GURLBase.)

With this I can jump over all the limitations with "gHttpExecuteHook ... IWServer ... IWServersession ..."
and it jumps me to my
procedure my_video_routine( ...
in which I can make a WebApplication.SendFile( ...)

that works.
Now I got problems to use SendStream (for dynamically get) instead of SendFile (for statically file), and I'm working on patching IW.HTTP.Reply to solve this, but this should be only work,no problem.
So the thread can be closed.
Jose Nilton Pace


Posts: 122
Registered: 5/15/98
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 9, 2016 9:49 AM   in response to: Adalbert Menhofer in response to: Adalbert Menhofer
Hi, put in the uses IWAppCache

Can you try:

procedure TIWForm1.IWButton1Click(Sender: TObject);
var
S: String;
begin
S := TIWAppCache.NewTempFileName('.mp4');

SaveYourOriginalMP4.SavetoFile( S );
or
SaveYourOriginalMP4.export( S );

WebApplication.SendFile(S, True, 'video/mp4', 'product.mp4' );
end;

Hope this help.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 9, 2016 12:01 PM   in response to: Adalbert Menhofer in response to: Adalbert Menhofer
Sorry, I misunderstood the problem. You definitely want to use Custom Content Handlers. Here is a link to the demo:
http://iwdemos.codeplex.com/SourceControl/latest#Atozed Demos/XIV/Delphi/CustomContentHandlers/

You should look at the ServerController 's Initialization section. There you will see the addition of a custom content handler, which allows the application to control everything directed to http://www.mydomain.com:8888/GiveMeSomeXML. With that extension you can also pass parameters like this http://www.mydomain.com:8888/GiveMeSomeXML?param1=value1.

with THandlers.Add('', 'GiveMeSomeXML', TContentXML.Create) do begin
   CanStartSession := True;
   RequiresSessionStart := False;
end;


The TContentXML is a custom class that allows you to define all processing on the /GiveMeSomeXML portion of your server. This would allow you to control the response and deliver anything you want. That class is defined in the IW.Content.XML file in the demo project. The code from that unit is really straight forward and easy to modify and adapt to your needs. Alexandre pointed me to this solution for another problem, but I have now found it useful for many features that I wanted to implement and control.

unit IW.Content.XML;
 
interface
 
uses
  Classes, IW.Content.Base, HTTPApp, IWApplication, IW.HTTP.Request, IW.HTTP.Reply;
 
type
  TContentXML = class(TContentBase)
  protected
    function Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication;
        aParams: TStrings): boolean; override;
  public
    constructor Create; override;
  end;
 
implementation
 
uses
  IW.Content.Handlers, IWMimeTypes, SysUtils;
 
constructor TContentXML.Create;
begin
  inherited;
  mFileMustExist := False;
end;
 
function TContentXML.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication;
 aParams: TStrings): boolean;
begin
  Result := True;
  if Assigned(aReply) then
  begin
    if aRequest.GetParams.Count=0 then
    begin
      aReply.ContentType := MIME_XML;
      aReply.WriteString('<xml>');
      aReply.WriteString('<note>');
      aReply.WriteString('  <to>Tove</to>');
      aReply.WriteString('  <from>Jani</from>');
      aReply.WriteString('	<heading>Reminder</heading>');
      aReply.WriteString('  <body>Don''t forget me this weekend!</body>');
      aReply.WriteString('</note>');
      aReply.WriteString('</xml>');
    end
    else
    begin
    //aReply.ContentType := MIME_XML;
      aReply.WriteString('aRequest.GetParams.Count='+IntToStr(aRequest.GetParams.Count));
    end;
  end;
  aSession.Terminate;
end;
 
initialization
 
end.


Edited by: Daniel Fields on Mar 9, 2016 12:09 PM
Adalbert Menhofer

Posts: 10
Registered: 4/10/03
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 9, 2016 5:31 PM   in response to: Adalbert Menhofer in response to: Adalbert Menhofer
Jose and Daniel, thank you very much.

Both Solutions do not fit my needs.

Following is a theoretical example to understand the requirement:

A video shall consist of three parts: a) Intro b) some Sheets c) Trailer

(a) and (c) are fixed; the part (b) will be made with series of frames which are for example generated by excel-Charts.
the excel-charts base on Parameters, which have been saved values of a previous html-page.

with that I can merge the parts (a), the generated part (b) and (c) to a mp4-file.

and as an additional requirement: there are 6 different keys which leads to 6 different series of Excel-Charts. So I need 6 fixed buttons:

src="/sess_files/video1.mp4"' ( for example, parameters are transposed to historical changes)
src="/sess_files/video2.mp4"' ( for example, historical is irrelevant, only actual data but in relation to other subjects)
...
src="/sess_files/video6.mp4"'


in Joses solution I have to calculate ALL video1-video6 and it doesn't matter, whether user needs only video2.
also, it would be too slow, because already I have a big stream and don't want to cache it on disk.

in Daniels solution I don't have information about the user input one page before, because THandler is outside UserContext (I think so)

so it seems dynamically generation of virtual files (as streams), which can be assigned to "src=..." is only possible with the callback,
today I succeeded in got this to work with dynamically set the src Attribute in javascript

elem_video.src= GURLBase + "callback?callback=my_video_routine&id=product.mp4"

, (also transferring additional parameters) and in the Delphi Project in Routine "my_video_routine" with "SendStream" sending the temp. generated Result-Stream.

But, thank you very much for your help - that will be helpful for me in other projects.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 9, 2016 5:49 PM   in response to: Adalbert Menhofer in response to: Adalbert Menhofer
You can send the SessionID as a parameter from the previous page. With that you can directly access the active UserSession in question. You could also pass whatever you need as parameters to the content handler. Everything is under the same umbrella. You have full control of everything you need.

That is similar to what you are trying to do with the callback.

Edited by: Daniel Fields on Mar 9, 2016 5:49 PM
Adalbert Menhofer

Posts: 10
Registered: 4/10/03
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 10, 2016 3:57 AM   in response to: Daniel Fields in response to: Daniel Fields
Hi Daniel,
this is a very interesting tip.
can I be shure, that there are no side effects (of course I must lock the user session, but others like blocking or with the threads or some counter that intraweb internally uses) ?
Jose Nilton Pace


Posts: 122
Registered: 5/15/98
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 10, 2016 4:48 AM   in response to: Adalbert Menhofer in response to: Adalbert Menhofer
Adalbert, look at this page:
http://docs.atozed.com/docs.dll/Classes/TIWAppCache.html

in this section:
StreamToCacheFile [Public]
Declaration: class function StreamToCacheFile(Sender: TObject; AStream: TStream; const AContentType: string; const ACacheType: TCacheType = ctSession): string;
Description: Creates a new cache file and save AStream content into it.
Parameters:
Sender (TObject): May have one of these values
If you are creating a Form cache file, Sender must be an instance of TIWForm class.
If you are creating a Session cache file, Sender must be an instance of TIWApplication class, or TIWForm class
If you are creating an Application cache file, this parameter is ignored, so NIL may be used.
AStream (TStream): Stream whose content will be saved into the cache file.
AContentType (string): Content type of the stream.
ACacheType (TCacheType, default ctSession): Type of cache that will be used. See TCacheType definition.
Result: (string) Contains the URL of the cache file.

CacheType ctSession

//This cache file will be "alive" during the whole user session (ACacheType = ctSession)

Maybe, you go for this direction.

I am newbie in IntraWeb and can´t help a lot.
Daniel Fields

Posts: 622
Registered: 11/29/04
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 10, 2016 12:13 PM   in response to: Adalbert Menhofer in response to: Adalbert Menhofer
I suggest this method because it is fully integrated into your existing server. All of the threading will be handled by the same process inside your application. IW does a great job of managing threads so you would just be building on top of that. I would still use TCriticalSections to ensure 100% thread safety, that is just good practice.

I would also access active user sessions for read-only purposes. You said that you draw upon information there to generate your files. That type of access would not interfere with anything. I have a function built into a ServerController that can tell me if a specific user is active on the system. It does that by scanning the active sessions and reading UserSession properties.

Here is some code that shows how you can access the Sessions list

procedure TIWServerController.SessionDemo(aid : string);
var List: TList;
    i: Integer;
    App: TIWApplication;
begin
  List:= GSessions.LockList;
  try
    for i:= 0 to List.Count-1 do
    begin
      App:= TIWApplication(List[i]); //each member is a full TIWApplication instance
      if (App.AppID = aid) then
       with TIWUserSession(App.Data) do //TIWUserSession(App.Data) is a complete instance of your TIWUserSession
       begin
 
       end;
    end;
  finally
    GSessions.UnLockList(List);
  end;
end;
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: different video download with same url
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 17, 2016 12:31 AM   in response to: Adalbert Menhofer in response to: Adalbert Menhofer
Both Solutions do not fit my needs.

You are ignoring how internet works and forcing "your solution" into the application.

When you just change the content of the file without changing its name, you are denying the fact that there are many agents between your application and the browser: The web server (it may be Indy, it may be IIS, Apache, whatever), routers and proxy servers in your network, proxy on the client network and finally the browser. ALL those agents by design will TRY to cache that file because this is how internet is designed. Imagine if each agent retrive the same image, video and sound over, over and over again????
You just need to review your application. When you try to do something that goes against how things are designed to work, you should just give a step back and review your design and requirements.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02