Magic User Group

Magic Wiki-Wakka : DownloadFilesFromWeb

HomePage :: CATEGORIES | Index :: Changes :: Comments :: Search :: Login/Register
Most recent edit on 2008-01-24 18:42:27 by AndreasSedlmeier [fixed broken links to eDeveloper online help at magicsoftware.com]

Additions:
Magic/eDeveloper has two functions which you can use from within your Internet application to send binary data and files thru the requester: File2Req() and Blob2Req().

Deletions:
Magic/eDeveloper has two functions which you can use from within your Internet application to send binary data and files thru the requester: File2Req() and Blob2Req().



Edited on 2007-04-04 02:21:55 by AndreasSedlmeier

Additions:
Implemented in above sample you'll also find "content negotiation" (to some extend). If the application f.i. finds by looking in the information the user's browser sends, that its actually a mobile device/browser (one which accepts WML or XHTML), it changes to a WML layout and avoids things which otherwise would be not supported by that device (cookies).
"Content-Negotiation" requires you to read some information the client's browser sends from Internet Server (CGI environment) variables.
See also:
- Internet Server (CGI environment) variables
external links:


Deletions:
See also / Further readings:



Edited on 2007-02-08 09:10:01 by AndreasSedlmeier

Additions:
If you put above "code" in a program "Download" within application "InternetTest" you could e.g. put a hyperlink on a html which looks like this:
<a href="/Magic94Scripts/MGrqispi94.dll?AppName=InternetTest&PrgName=Download">Download famous Test.pdf</a>
If you leave away the Content-Disposition header in the response to suggest the browser a filename, it dependens on the browser what name it suggests to you when it opens the file save dialog. Current versions of Mozilla (FireFox) will suggest "mgrqispi94.dll"; IE will suggest "mgrispi94.pdf".
If you want to ensure that your browser always tries to open a file after download, you can specify 'Content-Disposition: inline;'. If there's a registered application/plugin for the Content-Type you specified (or which was "sniffed" by the browser), the application will open.
At http://tech.groups.yahoo.com/group/magicu-l/files/fileupload_sample.v2.zip you find a sample Magic 9.4 application which shows howto upload and download files to and from Magic & Internet applications. It also has an "Options" screen. There you can set the "download style" (attachment | inline) for a particular user and test with your browser. This sample application defaults the "Content-Type" to "application/octet-stream" and then analyzes the file extension and checks the registry for a maybe registered content-type for this file extension.


Deletions:
If you put above "code" in a program "Download" within application "IneternetTest" you could e.g. put a hyperlink on a html which looks like this:
<a href="http://yourserver.domain.com/Magic94Scripts/MGrqispi94.dll?AppName=InternetTest&PrgName=Download">Download Test.pdf</a>
If you want to ensure that your browser always tries to open a file after download, you can specify 'Content-Disposition: inline;'.
At http://tech.groups.yahoo.com/group/magicu-l/files/fileupload_sample.v2.zip you find a sample Magic 9.4 application which shows howto upload and download files to and from Magic & Internet applications. It also has an "Options" screen. There you can set the "download style" (attachment | inline) for a particular user and test with your browser.

The sample application defaults the "Content-Type" to "application/octet-stream" and then analyzes the file extension and checks the registry for a maybe registered content-type for this file extension.




Edited on 2007-02-08 08:55:44 by AndreasSedlmeier

Additions:
Downloading files from a web server is not really a problem. Webservers cannot only serve .html; they can serve any kind of files. You place the file(s) in a directory where the (internet) users have read access because a virtual directory (alias) points to it and the file is accessible and available for download. All you need to tell your client is the URL for/to this file. You can put a link to this file on your website.
Often above solution is however not exactly what you want. You often have a Magic & Internet application running and you want that this application sends back the content of files to the clients. You want that your Magic & Internet application is at least "involved" in the process of downloading files from your webserver; at least for special content and files. Putting files in the webservers document root completely bypasses your application however. It does not get notified when files are downloaded; the only thing you can do to find out that a particular file actually has been downloaded is: scanning the webserver's logfiles (unless you find another way of notifying your Magic application like writing a IIS extension or module for Apache or similar things which are out of scope of this document to discuss).
Other reasons for not letting the webserver handle the downloads are: security and dynamic content.
You want that your application decides if a user is actually authorized to receive this file and you want to log the access to this file.
Sometimes you generate the files on the fly upon request (e.g. a pdf with a report).
Sometimes these files reside in a place where the internet server would have no access.
One way to solve this issues with "downloading files from webservers running Magic/eDeveloper applications" is the requester

Use requester to send files to (internet) users

In Magic it is the requester layer which connect a Magic & Internet applications with the Internet requester (and thereby indirectly with the client's browser).
Magic/eDeveloper has two functions which you can use from within your Internet application to send binary data and files thru the requester: File2Req() and Blob2Req().
Specifying content type and other things is around message exchange a big issue in the internet and the umbrella term for this is: MIME (Multipurpose Internet Mail Extensions). Originally invented for exchange of ASCII mail messages, this standard is meanwhile used for plenty of other purposes as well, e.g. the exchange and encoding of messages between a http server (IIS) and - client (IE) which is required to download files from an Internet server with unknown content.
Content-Type describes the data contained in the body of a message. The media type. It allows the user agent to pick an appropriate mechanism to present the data to the user. If the content type you specify is known to the user agent and its unambigious, it can pass this data to an application which is registerd fo this content-type (MIME type).
If you'ld analyze the Content-Type whic is set as a HTTP header when you click a file on a webpage to open it, you'ld see that this field is almost always set (particular then when its not html content).
Samples for Content-type are:

Content-Type: text/html; charset=ISO-8859-4
Content-Type: application/pdf
Content-Type and Content-Disposition for message bodies generated with a "web application" can be set as HTTP header fields. Before you send your data thru the requester with either File2Req() or Blob2Req() you should set the appropriate http header fields with the function RqHttpHeader().
For a complete description of what actually can be set in Content-Type and Content-Disposition header fields please consult the internet draft sdtandards (RFCs) listed in the reference section at the end of this document.
If the user clicks this, your program will be invoked and send test.pdf to the clients browser with content-type and content-disposition set as given in the sample above. The user's browser will recognize the data as .pdf and will find Acrobat reader as registered application (if its installed on the client's workstation).
- Multipurpose Internet Mail Extensions, (MIME) Part One


Deletions:
Downloading files from a web server is not really a problem. You place the file(s) in a directory where the (internet) users have read access because a virtual directory (alias) points to it and the file is accessible and available for download. All you need to tell your client is the URL for/to this file. You can put a link to this file on your website.
Often above solution is however not exactly what you want. You most often have a Magic & Internet application running and you want that this application sends back the content of files to the clients.
You want to do that if your application found out that the user is actually authorized to receive this file and you want to log the access to this file. Sometimes you generate the files on the fly upon request and sometimes these files reside in a place where the internet server would have no access.
In Magic it is the requester(s) which connect a Magic & Internet applications with the Internet server (and thereby indirectly with the client's browser) and Magic has two functions which you can use from within your Internet application to send binary data and files thru the requester: File2Req() and Blob2Req().
Specifying content type and other things is a big issue in the internet and the umbrella term for this is: MIME (Multipurpose Internet Mail Extensions). Originally invented for exchange of ASCII mail messages, this standard is meanwhile used for plenty of other purposes as well, e.g. the exchange and encoding of messages between a http server (IIS) and - client (IE) which is required to download files from an Internet server with unknown content.
Content-Type describes the data contained in the body of a message. It allows the user agent to pick an appropriate mechanism to present the data to the user. If the content type you specify is known to the user agent and its unambigious, it can pass this data to an application which is registerd fo this content-type (MIME type).
Content-Type and Content-Disposition for a web application can be set as HTTP header fields. Before you send your data thru the requester with either File2Req() or Blob2Req() you should set the appropriate http header fields with the function RqHttpHeader().
For a complete description of what actually can be set in Content-Type and Content-Disposition header fields pleas consult the internet draft sdtandards (RFCs).
If the user clicks this, your program will be invoked and send test.pdf to the clients browser with content-type and content-disposition set as given in the sample above. The user's browser will recognize the data as .pdf and will find Acrobat reader as registered application.




Oldest known version of this page was edited on 2007-02-07 18:46:32 by AndreasSedlmeier []
Page view:

Sending Files from Magic & Internet application to a browser thru Requester


Downloading files from a web server is not really a problem. You place the file(s) in a directory where the (internet) users have read access because a virtual directory (alias) points to it and the file is accessible and available for download. All you need to tell your client is the URL for/to this file. You can put a link to this file on your website.

Often above solution is however not exactly what you want. You most often have a Magic & Internet application running and you want that this application sends back the content of files to the clients.

You want to do that if your application found out that the user is actually authorized to receive this file and you want to log the access to this file. Sometimes you generate the files on the fly upon request and sometimes these files reside in a place where the internet server would have no access.

In Magic it is the requester(s) which connect a Magic & Internet applications with the Internet server (and thereby indirectly with the client's browser) and Magic has two functions which you can use from within your Internet application to send binary data and files thru the requester: File2Req() and Blob2Req().

File2Req takes a filename as its only parameter and sends the content of this file thru the requester; Blob2Req() takes a BLOB variable as its only parameter and sends this BLOB thru the requester. Blob2Req() used in conjunction with File2Blob() allows exactly the same as File2Req() alone.

If you use File2Req() to send a file thru the requester, your client's browser will receive a "binary stream of data". You need to help the client to find out what this stream of data actually "is". You need to specify the "content type" (although browsers will do some "MIME sniffing" on the data they get and eventually will find out themselves).

Specifying content type and other things is a big issue in the internet and the umbrella term for this is: MIME (Multipurpose Internet Mail Extensions). Originally invented for exchange of ASCII mail messages, this standard is meanwhile used for plenty of other purposes as well, e.g. the exchange and encoding of messages between a http server (IIS) and - client (IE) which is required to download files from an Internet server with unknown content.

The list of possible mime settings, -headers and directives is long; two of those most interesting for us to be able to download files sent thru the Magic Internet Requester(s) are:
- Content-Type
- Content-Disposition

Content-Type describes the data contained in the body of a message. It allows the user agent to pick an appropriate mechanism to present the data to the user. If the content type you specify is known to the user agent and its unambigious, it can pass this data to an application which is registerd fo this content-type (MIME type).

Content-Disposition is an optional header field for MIME messages to allow indication of a presentation mechanism and a archival disposition (a file name) to a user agent. By setting this header, you suggest the client what name it should give the file, you can add information about the file date, ... You can also suggest the user agent if it should treat this file like an attaqchment and save or trying to open it immediately.

Content-Type and Content-Disposition for a web application can be set as HTTP header fields. Before you send your data thru the requester with either File2Req() or Blob2Req() you should set the appropriate http header fields with the function RqHttpHeader().

For a complete description of what actually can be set in Content-Type and Content-Disposition header fields pleas consult the internet draft sdtandards (RFCs).

Look into following "code" snipplet:
Select Virtual (A) v.bfRet (Logical)
Select Virtual (B) v.ContentType (Alphanumeric, 128)
Select Virtual (C) v.ContentDisposition (Alphanumeric, 128)
Update B = 'Content-Type: application/pdf'
Update C = 'Content-Disposition: attachment; filename="test.pdf"'
Update A = RqHttpHeader(Trim(A), Trim(B))
Update A = File2Req('c:\temp\test.pdf')

If you put above "code" in a program "Download" within application "IneternetTest" you could e.g. put a hyperlink on a html which looks like this:
<a href="http://yourserver.domain.com/Magic94Scripts/MGrqispi94.dll?AppName=InternetTest&PrgName=Download">Download Test.pdf</a>


If the user clicks this, your program will be invoked and send test.pdf to the clients browser with content-type and content-disposition set as given in the sample above. The user's browser will recognize the data as .pdf and will find Acrobat reader as registered application.

Since you specified "attachment" in content-disposition, the browser will however not try to start Acrorbat reader with the .pdf as parameter; it will ask you if it should save the file. It will suggest test.pdf (as suggested by you in content-disposition) as filename.

If you want to ensure that your browser always tries to open a file after download, you can specify 'Content-Disposition: inline;'.

At http://tech.groups.yahoo.com/group/magicu-l/files/fileupload_sample.v2.zip you find a sample Magic 9.4 application which shows howto upload and download files to and from Magic & Internet applications. It also has an "Options" screen. There you can set the "download style" (attachment | inline) for a particular user and test with your browser.

The sample application defaults the "Content-Type" to "application/octet-stream" and then analyzes the file extension and checks the registry for a maybe registered content-type for this file extension.



See also / Further readings:
- RFC 1867 - Form-based File Upload in HTML - with eDeveloper
- The Content-Disposition Header Field
- MIME Type Detection in Internet Explorer
- eDeveloper online help on File2Req, Blob2Req, RqHTTPHeader



CategoryWeb
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki trunk
Page was generated in 0.1683 seconds