Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: BLOB's and Webserver

Re: BLOB's and Webserver

From: mark tomlinson <marktoml_at_gdi.net>
Date: Fri, 29 May 1998 15:01:39 GMT
Message-ID: <3572cae3.160895755@newshost.us.oracle.com>


We had a CGI executable that did this, (on NT), here is the code if you want.

The parameters tell it what the FILE# is for retrieval from the table

---html source for this---------------------------------------
<HR>
</FORM>

<center>
<A
HREF="http://myurl.us.oracle.com/agent/blob_dn/27/general.zip">Download File: general.zip</A>
Uploaded on: 09-JAN-97 Size: 29590
<IMG SRC="/gif/upload.gif">
<BR>
</center>

---C++ code --------------------------------------------------------

#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <fcntl.h>

extern "C" {
#include <ociapr.h>

}

// Define the OCI datatypes
#define VARCHAR2_TYPE 1
#define NUMBER_TYPE 2
#define INT_TYPE 3
#define FLOAT_TYPE 4
#define STRING_TYPE 5
#define ROWID_TYPE 11
#define DATE_TYPE 12
#define LONG_RAW 24
#define LONG_VARRAW 95

// Define the std streams
#define STDIN 0
#define STDOUT 1
#define STDERR 2

//#define text otext

void main()
{

        // Data members for the INPUT data stream
        char* dataraw;          // The raw data
        int       fileno = 0;   // The file reference number

        char* parmtmp;          // This is a working area to extract
parameters
        /*      
         *      Begin processing the INPUT stream
         */
        
        // Flip the stdin stream to binary mode
        setmode( STDIN,  _O_BINARY );

        // Get the URL string and parse it out
        dataraw = strlwr(strdup(getenv("PATH_INFO")));

        // Pull the parameter FILENO out of the path header
        parmtmp = strdup(dataraw+1);
        strtok(parmtmp,"/\\");
        fileno = atoi(parmtmp);

        if (fileno == 0)
        {
                printf( "Content-Type: text/plain\n\nInvalid URL value
string\n" );
                return;
        }

        /*      
         *      Time for a little OCI to fetch our data!!!
         */

        Cda_Def lda;
        Cda_Def cda;
        char    hda[256];

        char    filetyp[50];    // The type of binary file
        char    filename[50];   // The name of binary file
        long    filelen;                // The length of the binary
data
        char    fileext[4];     // the file extension
        char*   filedat;                // The binary file data

        char  filehdr[100];             // The outstream heade

        short   i_fileno  = 0;
        short   i_refno   = 0;
        short   i_filenam = 0;
        short   i_filetyp = 0;
        short   i_filelen = 0;
        short   i_filedat = 0;

        memset(hda,0,255);
    memset(filename,0,50);
        if

(olog(&lda,(text*)&hda,(text*)"scott/tiger_at_beq-local",-1,0,-1,0,-1,OCI_LM_DEF))

        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Logon:", lda.rc );

        if (oopen(&cda,&lda,0,-1,-1,0,-1)) 
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Open:",
cda.rc );

        if (oparse(&cda,(text*)"select len, type, name from blobtab where file# = :fileno",

                -1,1,2))
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Parse:",
cda.rc );  

        if
(obndra(&cda,(text*)":fileno",-1,(text*)&fileno,sizeof(int),INT_TYPE,-1,

                &i_refno,0,0,0,0,0,-1,-1))
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Bind:",
cda.rc );

        if
(odefin(&cda,1,(text*)&filelen,sizeof(int),INT_TYPE,-1,&i_filelen,0,0,-1,0,0))

        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Define 1:", cda.rc );

        if
(odefin(&cda,2,(text*)filetyp,50,STRING_TYPE,-1,&i_filetyp,0,0,-1,0,0))

        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Define 2:", cda.rc );

        if
(odefin(&cda,3,(text*)filename,50,STRING_TYPE,-1,&i_filenam,0,0,-1,0,0))

        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Define 3:", cda.rc );

        if (oexec(&cda))
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Exec:",
cda.rc );
        if (ofetch(&cda))
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Fetch:",
cda.rc );

        filedat = (char*) malloc(filelen);

        if (oparse(&cda,(text*)"select data from blobtab where file# = :fileno",

                -1,1,2))
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Parse:",
cda.rc );

        if
(obndra(&cda,(text*)":fileno",-1,(text*)&fileno,sizeof(int),INT_TYPE,-1,

                &i_refno,0,0,0,0,0,-1,-1))
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Bind:",
cda.rc );
        
        if
(odefin(&cda,1,(text*)filedat,filelen,LONG_RAW,-1,&i_filedat,0,0,-1,0,0))
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Define:",
cda.rc );
        if (oexec(&cda))
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Exec:",
cda.rc );
        if (ofetch(&cda))
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Fetch:",
cda.rc );
        if (ocan(&cda))
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Cancel:",
cda.rc );
        if (ologof(&lda)) 
        printf( "Content-Type: text/plain\n\n%s\t%i\n", "Logoff:",
lda.rc );
        /*      
         *      Begin processing the OUTPUT stream
         */

        // Stream out the binary data to stdout
        setmode( STDOUT,  _O_BINARY );

        // Setup the stream header
        memset(fileext,0,4);
        strcpy(fileext,strstr(filename,".")+1);
        _strupr(fileext);
        if(strcmp(fileext,"ZIP") == 0)  {
            strcpy(filetyp, "application/x-compressed;");       // ZIP
files...
        }
        else    {
                if(strncmp(fileext,"XL",2) == 0)        {
                    strcpy(filetyp, "application/x-msexcel;");  //
Excel files...
                }
                else    {
                    strcpy(filetyp, "application/octet-stream;");
// This was chosen aribitrarily as the default
                }
        }
        sprintf( filehdr, "Content-Type: %sname=\"%s\"\n\n", filetyp,
filename );
        // Stream out the data stream
        fwrite( filehdr, 1, strlen(filehdr), stdout);
        fwrite( filedat, 1, filelen, stdout);

        return;

} Received on Fri May 29 1998 - 10:01:39 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US