NetTalk Central

Author Topic: Individual URL for download, with UID  (Read 4036 times)

Wolfgang Orth

  • Sr. Member
  • ****
  • Posts: 251
    • View Profile
    • oData Wolfgang Orth
Individual URL for download, with UID
« on: March 15, 2017, 11:35:25 AM »
Hello all and Bruce,

my intention is to provide files for download, however I do not want to name the "physical" location of those ZIPs, but an "artificial" one.

Instead of http://server.com/downloads/new.zip I think of something like this:

http://server.com/aow27ensz6tb/new.zip which actually points to the file in the first URL.

Something like this aow27ensz6tb is an individual UID per customer. With a SOAP-method its easy to identify them, but those links will be part of a newsletter.

The idea is to track, which customer has taken the occasion to fetch the recent update. That does not necessarily mean the update gets installed at all, but it helps to identify those customers, who are definetily not up-to-date. They can be approached in a different way then. Its about a hosputal drug database, so there are good reasons for them to be updated.

First question: Is it possible to create individual links pointing to a physical location and how?

Second question: Where would be the best spot to intercept that UID from the URL, to store into a table?

Thanks in advance,
Wolfgang

Stu

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
    • Email
Re: Individual URL for download, with UID
« Reply #1 on: March 15, 2017, 02:41:38 PM »
G'day Wolfgang!

This is absolutely possible. In fact, it's now an integral part of all of our systems, the idea that you send out a url that doesn't actually exist.

You'll want a function that returns a url (especially helpful if you have automated systems for sending those links out via whatever).

And you'll want Webhandler to know how to interpret and deal with that link.

I'm away from my desk at the moment, so will get back to this with specifics. It's the _ProcessLink and possibly _TranslateFilename embeds in question. Basically you can take in the url and change what is sent back. The url is all that the person and it's browser sees. The file, it can be whatever you want, from whereever you want (within limits).

Anyway, will be back later with specifics.
Cheers,

Stu Andrews

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Individual URL for download, with UID
« Reply #2 on: March 15, 2017, 09:53:51 PM »
I've always used _SendFile to do the switch. Bruce covers it to some extent in his book.

Wolfgang Orth

  • Sr. Member
  • ****
  • Posts: 251
    • View Profile
    • oData Wolfgang Orth
Re: Individual URL for download, with UID
« Reply #3 on: March 16, 2017, 11:36:23 AM »
> Anyway, will be back later with specifics.

Thats would be cool!

tia
Wolfgang

Wolfgang Orth

  • Sr. Member
  • ****
  • Posts: 251
    • View Profile
    • oData Wolfgang Orth
Re: Individual URL for download, with UID
« Reply #4 on: March 16, 2017, 11:39:42 AM »
> in his book.

hmmm, now that you say that.... I have the printed version.... somewhere....

Where have I put that?

I suspect I have to plow through my dusty shelves.

Stu

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
    • Email
Re: Individual URL for download, with UID
« Reply #5 on: March 16, 2017, 09:37:49 PM »
Hi Wolfgang,

Okay, so, here's the gist of what my code does (although Bruce's book/code would surely be simpler and more profound, ha).

1. Code goes into the _SendFile embed. I was (and still do for a couple of little things) using the _TranslateFileName embed to redirect a file and rewrite the url, but there are length issues with what is passed to and fro. Anyway, _SendFile!

2. You want to get a couple of StringTheory vars going on, very very helpful for doing file stuff.

3. You need to get to the point of knowing the url is something you want to allow for a custom download (ie my code splits the url into segments based on the \)

Something like this: Url: <purpose>\<context>\<guid1> or <subcontext>\<guid2> or <guid1>

4. Once you get there, you start setting the file information for the webserver.

For example, here's the psuedo code for one type of download file option I use. The str_DownloadFile StringTheory var has the absolute path of the file you want to download.

Code: [Select]
self.ForceNoCache = 1
str_Filename.SetValue(str_DownloadFile.FileNameOnly())
self.ReplyContentType = 'application/'&str_DownloadFile.ExtensionOnly()
p_Header = NET:SendHeader + NET:DontCache
self.ForceNoCache = 1
self.HeaderDetails.ContentDisposition = 'attachment;filename="'&str_Filename.GetValue()&'"'

5. Now, this is important. You don't want the default webserver functionality to happen. So at the bottom of the _SendFile embed BEFORE the parent call you need an if statement that starts, and it finishes in the AFTER parent call embed.

The code at the bottom of your _SendFile embed would look something like:

Code: [Select]
if (customdownloadflag = 1)
self._SendFile(str_DownloadFile.GetValue(),p_Header)

Then at the start (really it's the only thing) of the embed AFTER the parent call, you end your if statement:

Code: [Select]
end
Cheers,

Stu Andrews

Stu

  • Hero Member
  • *****
  • Posts: 509
    • View Profile
    • Email
Re: Individual URL for download, with UID
« Reply #6 on: March 16, 2017, 09:39:59 PM »
Forgot something.

At the top of the _SendFile embed, there's a StringTheory var that holds the url.

Code: [Select]
str_Url.Free(); str_Url.FreeLines();
str_Url.SetValue(clip(p_Filename))
str_Url.Remove(clip(GLO:ProgramPath)&'web\')
str_Url.Split('\')
if (str_Url.GetLine(str_Url.Records()) = '') then str_Url.DeleteLine(str_Url.Records()) .

You can then perform various tests on this, and case the segments to be able to know what to do.

Code: [Select]
!* Check *
case lower(str_Url.ExtensionOnly())
of 'jpg' orof 'png'
else

  !* Case the first segment of the url *
  case lower(str_Url.GetLine(1))
Cheers,

Stu Andrews