genexus

Download a file from BlobFile attribute


I'm testing a bit with blobfile data type in Genexus but I can't understand how to download a file I have previously saved in it, the wiki page didn't help. The attribute has not methods or thing that looks useful. Someone can help me?


Solution

  • Using a proc with HTTP call protocol and returning the file.

    Suppose you have a transaction with this structure:

    FilesToDownloadId*

    FilesToDownloadFile - Defined as BlobFile

    Suppose you have a Webpanel with a grid showing a list of files (both attributtes) and &Download variable is just a char variable to use the "link" function.

    Event Load
        &Download="Download"
        &Download.Link=DownloadFile.Link(FilesToDownloadId)
    Endevent
    

    DownloadFile is a proc with "Call Protocol" property set to HTTP.

    This proc is:

    Rules: parm( IN:FilesToDownloadId );

    for each
        &HttpResponse.AddHeader(!'Content-Type',  FilesToDownloadFile.FileType)
        &HttpResponse.AddHeader(!'Content-Disposition', !'attachment; filename=' + FilesToDownloadFile.FileName+"."+FilesToDownloadFile.FileType)
        &blob=FilesToDownloadfile
        &HttpResponse.AddFile(&Blob)
    endfor
    

    Vars:

    &Blob - Blob

    &ContentType - Varchar(40)

    &HttpResponse - HTTPResponse