How does IE downloading is achieved? - web-services

I often click on a file link in the IE and a download box just pops out. But what happens behind this scene? I know that IE always talks to web server with HTTP protocol, and HTTP is text based.
So is IE download achieved with HTTP protocol? If so, how could arbitrary file format be downloaded over a text based protocol?
And I am currently trying to make a web app which will direct my customer to download some file. My current design is to implement a web service. Customer will call this web service and the web service will return the file download URL. But then I don't know what to do with the URL. Could I just use something like File.Copy to copy the file from the URL to local disk? Or how should I treat the URL? If there's a better design, please teach me.
Many thanks...

By specifying the right content type, you can tell the browser what kind of data it is you are sending.
In addition, there are special encodings (like Base 64) that allow binary content to be displayed as text, using only a limited set of characters and escaping everything else.
Then, there is nothing you need to do with the url. IE will know whether it can or cannot open the file and will show the download box accordingly.

maybe it's like
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>

Related

Windows update KB5003637 seems to have broken WebBrowser control, does anyone know why?

The recent Windows 10 update for KB5003637 seems to have caused our use of the WebBrowser control to fail. Our applications use a C++ dialog that hosts a web browser control based on the IWebBrowser2 interface and implemented by the COM class 8856f961-340a-11d0-a96b-00c04fd705a2. The control interacts with a bespoke internal 'web server' that is hosted on a localhost port. The web browser is rendering dynamic HTML with a bunch of css and javascript. It's a legacy app that has been working reliably for many years.
Our users that have Windows 10 versions 2004, 20H2, and 21H1 are installing the KB5003637, and when they do the web browser does not render the content that it did before.
Looking at some trace, I can see that the Web Browser is requesting the page's HTML, which seems to be delivered as it should. What normally happens at that time is that the web browser control requests the css and javascript files needed to make the page active. What happens instead is nothing.
The KB5003637 update is pretty big, but does contain fixes for some scripting vulnerabilities described in CVE-2021-31959 which are very much on point. Nothing that I've found so far indicates how this was fixed, the effect that it has on the WebBrowser control, nor what workarounds there might be.
Any help would be appreciated.
Turns out that the Windows update I described did change the behavior of the WebBrowser control. Our bespoke web server was not including content type headers for responses to the WebBrowser's request. For the last decade or more, the control was successfully able to figure out what the content was OR it defaulted to the correct content type in the cases that mattered. After the update, the WebBrowser was defaulting to a content type of 'text' for the initial HTML payload. As a result it was not trying to interpret the payload as HTML and therefore no further actions were necessary (like requesting css and js files).
When I changed the code to include a content type header of "text/html" for the initial payload, the application began working. Content type headers are now included with all replies.

manipulation the original source of a file or video url like youtube player or cloud file download sites

if we see big websites like youtube, google drive, facebook, cloud file download sites, etc., then we will find that every link file, video, image or whatever, then the original file link will not be seen for example videos on youtube, even if we inspect the element and see the source on the video player it isn't visible, the link is just written:
src = "https://www.youtube.com/94118230-9dbf-4207-a098-de7a7ccdf7f6"
without any real address or file extension like .mp4 or others. can anyone help explain how to engineer this and whether django can handle engineering like this?
First point: an url doesn't have to point to a file. What happens when some url is requested is up to the HTTP server serving the url. Serving files from the server's filesystem is the basic default for most HTTP servers (static sites), but that's just one of the possibilies, it can as well be executing a CGI script, delegating to a pool of long running processes (typical Python wsgi app), whatever...
Second point: files extensions are mostly cosmetic. You can have a file name without any extension directly served by Apache, and you can have an url with a filename extension that is actually served by some script or other program dynamicall generating content.
IOW, there's absolutely no relation between what the url looks like and how the response is built, and "original file link" doesn't mean anything, and the youtube url you posted IS as much of a "real address" than any other url.
can anyone help explain how to engineer this
It's impossible to answer this question, at least not with a one-size-fits-all answer. If all you want is to serve a static file without extension, just rename the file without the extension, possibly tweak your HTTP server config so that it correctly handles the case, and you're done.
whether django can handle engineering like this
Any techno that is not able to "handle engineering like this" is either prehistoric or fundamentally broken.
I strongy suggest you (seriously) read about the HTTP protocol and learn to set up and configure a standard HTTP server (Apache comes to mind). Only then will it make sense to worry about specific technos (Django or else).

Receive large file by parts from webservice

I have a webservice that processes and dynamically generates a PDF file from several smaller files. I also have a client application (website) from which users can download the PDF file.
Sometimes the result PDF is very large, and because of memory and response time restrictions the website user is not able to download it.
I am trying to find a way to make my website receive smaller packages, or something like that, and gradually display it in the user browser. Something similar to a video stream, but with PDF files. Is there any way I can accomplish that?
*EDIT: I found Mozilla's PDF.js a client-side PDF viewer built with HTML5 that I think would be useful to my issue, but I still haven't found in the docs how to solve the problem.
The solution proposed by Dan O would help me to improve the user experience, but not the memory problem in my server (webservice) and total time to process the PDF.
use HTTP chunking. Briefly:
set the Transfer-Encoding: chunked header in your HTTP response
send your PDF file in chunks using the following format:
<chunk size in bytes>
\r\n
<chunk of data>
\r\n
send an empty chunk to tell your user's browser that no more data is coming:
0
\r\n
\r\n

How to send a post request via excel to a RESTful Web Service without using XML?

Here's the deal: I had a excel table that fulfills a MySQL table. I already made a procedure in server side who receives the sheet, read it and put it on the database. Saddly the sheet and data table doesn't have the same structure, so I need to use a php object/script in server side to manipulate it. I have a interface to upload the file (excel file), so the PHP program can read it...
...but my boss job isn't make my life easier, is it? NO! He says that is a lot of work have to upload every excel file by the web interface. So, he asked me to make a button in the sheet that he might click after his "job" is done. That would replace the web interface.
But, the system itself is a interface that would be saled one day (well, it's the plan!). So, I just can't just role out the web interface.
WHAT I'M ASKING IS: There's a way that I could send a file (the sheet itself) in a post method straight from the VBA Macro without using XML files and name each data that I'm sending, like a form post?
So far, I've found some tutorials or even some SO posts that made me get somewhere. But all of them were talking about a XML, and I already have a method that receives a HTTP POST (from a form) and work. I aiming to reuse the same method. From my VBA script I'm already able to make the request (not a big deal) and post it. But, in the server-side script, I'm expecting a POST come out from a form, so it calls a field's name. I don't seen to be able to do that from a VBA post. =/
Here's the answer... the two first functions/methods define how to send a file to a web service. You only need the file path and the URL from service. It has answered even more than I expected. :D

Visitors to site get a file download instead of web page?

Why do visitors to my site sometimes get a download to a file instead of the page to which they were supposed to go?
What problem does that point to - browser, controller, or something?
Could possibly be that your HTTP server isn't providing the correct MIME type?
This usually means your web server is serving the page up as the wrong MIME type. You need to tell it which files should be served using which MIME types. Apache includes a standard file for this, but I'm not sure which web server or platform you're using.
Either you have an invalid mime type configured when serving the page, so the browser thinks the content type is something it has to download because it can't display it, or if the problem happens only to some users, then the mime type you are choosing is something that those specific users don't have their browsers configured to support.