Upload C Library Reference
Upload
Chilkat Upload is a freeware C library that can be used to upload files over HTTP and HTTPS to a web server.
- Supports both HTTP and HTTPS protocols.
- Progress monitoring with percentage completion and "heartbeat" monitoring.
- Abort capability.
- Asynchronous uploads with real-time monitoring of percentage completion and number of bytes transferred.
- Add arbitrary HTTP POST form parameters to your upload.
- Upload multiple files in a single transaction.
- Add arbitrary (custom) HTTP header fields to the HTTP upload.
- Retrieve the HTTP response status, header, and body returned by the web server.
Create/Dispose
HCkUpload CkUpload_Create(void);
Creates an instance of the CkUpload object and returns a handle (i.e. a "void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.
void CkUpload_Dispose(HCkUpload handle);
Objects created by calling CkUpload_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.
C "Properties"
int CkUpload_getChunkSize(HCkUpload handle); void CkUpload_putChunkSize(HCkUpload handle, int newVal);
The chunk size (in bytes) used by the underlying TCP/IP sockets for uploading files. The default value is 2048. This property is not typically modified.
void CkUpload_getHostname(HCkUpload handle, HCkString retval); void CkUpload_putHostname(HCkUpload handle, const char *newVal);
The hostname of the HTTP server that is the target of the upload. Do not include "http://" in the hostname. It can be a hostname, such as "www.chilkatsoft.com", or an IP address, such as "168.144.70.227".
int CkUpload_getIdleTimeoutMs(HCkUpload handle); void CkUpload_putIdleTimeoutMs(HCkUpload handle, int newVal);
A timeout in milliseconds. The default value is 30000. If the upload hangs (i.e. progress halts) for more than this time, the component will abort the upload. (It will timeout.)
void CkUpload_getLastErrorHtml(HCkUpload handle, HCkString retval);
Error information in HTML format for the last method called.
void CkUpload_getLastErrorText(HCkUpload handle, HCkString retval);
Error information in plain-text format for the last method called.
void CkUpload_getLastErrorXml(HCkUpload handle, HCkString retval);
Error information in XML format for the last method called.
void CkUpload_getLogin(HCkUpload handle, HCkString retval); void CkUpload_putLogin(HCkUpload handle, const char *newVal);
The HTTP login for sites requiring authentication. Chilkat Upload supports Basic HTTP authentication.
unsigned long CkUpload_getNumBytesSent(HCkUpload handle);
After an upload has completed, this property contains the number of bytes sent. During asynchronous uploads, this property contains the current number of bytes sent while the upload is in progress.
void CkUpload_getPassword(HCkUpload handle, HCkString retval); void CkUpload_putPassword(HCkUpload handle, const char *newVal);
The HTTP password for sites requiring authentication. Chilkat Upload supports Basic HTTP authentication.
void CkUpload_getPath(HCkUpload handle, HCkString retval); void CkUpload_putPath(HCkUpload handle, const char *newVal);
The path part of the upload URL. Some examples:
If the upload target (i.e. consumer) URL is: http://www.freeaspupload.net/freeaspupload/testUpload.asp, then
Hostname = "www.freeaspupload.net"
Path = "/freeaspupload/testUpload.asp"
If the upload target URL is http://www.chilkatsoft.com/cgi-bin/ConsumeUpload.exe, then
Hostname = "www.chilkatsoft.com"
Path = "/cgi-bin/ConsumeUpload.exe"
unsigned long CkUpload_getPercentUploaded(HCkUpload handle);
Contains the current percentage completion (0 to 100) while an asynchronous upload is in progress.
int CkUpload_getPort(HCkUpload handle); void CkUpload_putPort(HCkUpload handle, int newVal);
The port number of the upload target (i.e. consumer) URL. The default value is 80. If SSL is used, this should be set to 443 (typically).
void CkUpload_getProxyDomain(HCkUpload handle, HCkString retval); void CkUpload_putProxyDomain(HCkUpload handle, const char *newVal);
The domain name of a proxy host if an HTTP proxy is used. Do not include the "http://". The domain name may be a hostname, such as "www.chilkatsoft.com", or an IP address, such as "168.144.70.227".
void CkUpload_getProxyLogin(HCkUpload handle, HCkString retval); void CkUpload_putProxyLogin(HCkUpload handle, const char *newVal);
If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy login.
void CkUpload_getProxyPassword(HCkUpload handle, HCkString retval); void CkUpload_putProxyPassword(HCkUpload handle, const char *newVal);
If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy password.
long CkUpload_getProxyPort(HCkUpload handle); void CkUpload_putProxyPort(HCkUpload handle, long newVal);
The port number of a proxy server if an HTTP proxy is used.
void CkUpload_getResponseBody(HCkUpload handle, HCkByteData retval);
An HTTP upload is nothing more than an HTTP POST that contains the content of the files being uploaded. Just as with any HTTP POST or GET, the server should send an HTTP response that consists of header and body. This property contains the body part of the HTTP response.
void CkUpload_getResponseHeader(HCkUpload handle, HCkString retval);
An HTTP upload is nothing more than an HTTP POST that contains the content of the files being uploaded. Just as with any HTTP POST or GET, the server should send an HTTP response that consists of header and body. This property contains the header part of the HTTP response.
int CkUpload_getResponseStatus(HCkUpload handle);
The HTTP response status code of the HTTP response. A list of HTTP status codes can be found here: HTTP Response Status Codes.
BOOL CkUpload_getSsl(HCkUpload handle); void CkUpload_putSsl(HCkUpload handle, BOOL newVal);
Set this to true if the upload is to HTTPS. For example, if the target of the upload is:
https://www.myuploadtarget.com/consumeUpload.asp
then set:
Ssl = true
Hostname = "www.myuploadtarget.com"
Path = "/consumeupload.asp"
Port = 443
unsigned long CkUpload_getTotalUploadSize(HCkUpload handle);
The total size of the upload (in bytes). This property will become set at the beginning of an asynchronous upload. A program may monitor asynchronous uploads by tracking both NumBytesSent and PercentUploaded.
This property is also set during synchronous uploads.
BOOL CkUpload_getUploadInProgress(HCkUpload handle);
Set to true when an asynchronous upload is started. When the asynchronous upload is complete, this property becomes equal to false. A program will typically begin an asynchronous upload by calling BeginUpload, and then periodically checking the value of this property to determine when the upload is complete.
BOOL CkUpload_getUploadSuccess(HCkUpload handle);
Set to true (success) or false (failed) after an asynchronous upload completes or aborts due to failure. When a program does an asynchronous upload, it will wait until UploadInProgress becomes false. It will then check the value of this property to determine if the upload was successful or not.
BOOL CkUpload_getUtf8(HCkUpload handle); void CkUpload_putUtf8(HCkUpload handle, BOOL newVal);
To be documented soon...
void CkUpload_getVersion(HCkUpload handle, HCkString retval);
The version of the Chilkat Upload component, such as "2.0.0".
C "Methods"
void CkUpload_AddCustomHeader(HCkUpload handle, const char *name, const char *value);
Adds a custom HTTP header to the HTTP upload.
void CkUpload_AddFileReference(HCkUpload handle, const char *name, const char *filename);
Adds a file to the list of files to be uploaded in the next call to BlockingUpload, BeginUpload, or UploadToMemory. To upload more than one file, call this method once for each file to be uploaded.
void CkUpload_AddParam(HCkUpload handle, const char *name, const char *value);
Adds a custom HTTP request parameter to the upload.
BOOL CkUpload_BlockingUpload(HCkUpload handle);
Uploads files in a synchronous manner. This method does not return until all files have been uploaded, or the upload fails. The files to be uploaded are indicated by calling AddFileReference once for each file (prior to calling this method). Returns TRUE for success, FALSE for failure.
BOOL CkUpload_SaveLastError(HCkUpload handle, const char *filename);
Saves the last error information to an XML formatted file.
void CkUpload_SleepMs(HCkUpload handle, int millisec);
A convenience method for putting the calling process to sleep for N milliseconds. It is provided here because some programming languages do not provide this capability, and sleeping for short increments of time is helpful when doing asynchronous uploads.
BOOL CkUpload_UploadToMemory(HCkUpload handle, HCkByteData dataBuf);
Writes the complete HTTP POST to memory. The POST contains the HTTP header, any custom params added by calling AddParam, and each file to be uploaded. This is helpful in debugging. It allows you to see the exact HTTP POST sent to the server if BlockingUpload or BeginUpload is called.
const char *CkUpload_hostname(HCkUpload handle);
The hostname of the HTTP server that is the target of the upload. Do not include "http://" in the hostname. It can be a hostname, such as "www.chilkatsoft.com", or an IP address, such as "168.144.70.227".
const char *CkUpload_lastErrorHtml(HCkUpload handle);
Error information in HTML format for the last method called.
const char *CkUpload_lastErrorText(HCkUpload handle);
Error information in plain-text format for the last method called.
const char *CkUpload_lastErrorXml(HCkUpload handle);
Error information in XML format for the last method called.
const char *CkUpload_login(HCkUpload handle);
The HTTP login for sites requiring authentication. Chilkat Upload supports Basic HTTP authentication.
const char *CkUpload_password(HCkUpload handle);
The HTTP password for sites requiring authentication. Chilkat Upload supports Basic HTTP authentication.
const char *CkUpload_path(HCkUpload handle);
The path part of the upload URL. Some examples:
If the upload target (i.e. consumer) URL is: http://www.freeaspupload.net/freeaspupload/testUpload.asp, then
Hostname = "www.freeaspupload.net"
Path = "/freeaspupload/testUpload.asp"
If the upload target URL is http://www.chilkatsoft.com/cgi-bin/ConsumeUpload.exe, then
Hostname = "www.chilkatsoft.com"
Path = "/cgi-bin/ConsumeUpload.exe"
const char *CkUpload_proxyDomain(HCkUpload handle);
The domain name of a proxy host if an HTTP proxy is used. Do not include the "http://". The domain name may be a hostname, such as "www.chilkatsoft.com", or an IP address, such as "168.144.70.227".
const char *CkUpload_proxyLogin(HCkUpload handle);
If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy login.
const char *CkUpload_proxyPassword(HCkUpload handle);
If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy password.
const char *CkUpload_responseHeader(HCkUpload handle);
An HTTP upload is nothing more than an HTTP POST that contains the content of the files being uploaded. Just as with any HTTP POST or GET, the server should send an HTTP response that consists of header and body. This property contains the header part of the HTTP response.
const char *CkUpload_version(HCkUpload handle);
The version of the Chilkat Upload component, such as "2.0.0".
|