Search code examples
nsiswininet

Resolve file name on url redirect


I use wininet (with an nsis plugin called inetc) to download a file.

I want to save the file with the same file name that is used in the url for example http://some.domain.com/myfile.doc should be saved as myfile.doc. The problem is when I have a url with redirection. For example I can get http://some.domain.com/ which redirects to http://some.domain.com/myfile.doc, and I want to save it as myfile.doc.

How do I tackle this problem?


Solution

  • INetC was not really designed to support that but I guess you could call INetC::head in a loop and parse the returned header until it is no longer a redirect...

    Edit:

    Since INetC is only designed to deal with files named by the caller it just relies on the high-level WinInet default handling.

    While it might be possible to modify INetC or create a new plugin, it might be less work to just have the server do the work. It could return the content-disposition header that INetC::head can download or a special URL like server.com/?getname that just returns the name so you grab the name first with INetC::get and then perform the real INetC::get with the correct destination filename...