WriteCGIData()

Syntax

Result = WriteCGIData(*Buffer, Size)
Description
Writes binary data to the CGI output. When sending binary data, the 'content-type' header should be set to 'application/octet-stream'.

Parameters

*Buffer The memory buffer to write.
Size The size (in bytes) to write.

Return value

Returns non-zero if the data has been successfully written to the CGI output.

Example

  If Not InitCGI() Or Not ReadCGI()
    End
  EndIf
  
  WriteCGIHeader(#PB_CGI_HeaderContentType, "application/octet-stream")
  WriteCGIHeader(#PB_CGI_HeaderContentDisposition, "attachment; filename=image.png", #PB_CGI_LastHeader)
  
  If ReadFile(0, #PB_Compiler_Home + "examples/sources/data/world.png")
    Size = Lof(0)
    *Buffer = AllocateMemory(Size)
    ReadData(0, *Buffer, Size) ; Read the whole file into the new allocated buffer
    
    WriteCGIData(*Buffer, Size) ; Write the whole buffer to the CGI output
    
    CloseFile(0)
  EndIf

See Also

InitCGI(), WriteCGIHeader(), WriteCGIFile()

Supported OS

All

<- WaitFastCGIRequest() - CGI Index - WriteCGIFile() ->