WebUploadFileEx Function  
 
BOOL WINAPI WebUploadFileEx(
  LPCTSTR lpszLocalFile,  
  LPCTSTR lpszObjectLabel,  
  LPCTSTR lpszAppId,  
  DWORD dwStorageType,  
  DWORD dwAttributes,  
  DWORD dwReserved,  
  DWORD dwTimeout,  
  LPWEB_STORAGE_OBJECT lpObject,  
  WEBEVENTPROC lpEventProc,  
  DWORD_PTR dwParam  
);

The WebUploadFileEx function uploads the contents of a local file and creates or overwrites a storage object.

Parameters

lpszLocalFile
A null-terminated string that specifies the name of the local file that will be created or overwritten with the contents of the storage object. If a path is not specified, the file will be created in the current working directory.
lpszObjectLabel
A null-terminated string that specifies the label of the object that should be retrieved from the server.
lpszAppId
A null-terminated string which specifies the application ID for the storage container. The application ID is a string that uniquely identifies the application and can only contain letters, numbers, the period and the underscore character. If this parameter is NULL or an empty string, the default identifier SocketTools.Storage.Default will be used.
dwStorageType
An integer value that identifies the storage container type. One of the following values should be specified:
Value Description
WEB_STORAGE_GLOBAL Global storage. Objects stored using this storage type are available to all users. Any changes made to objects using this storage type will affect all users of the application. Unless there is a specific need to limit access to the objects stored by the application to specific domains, local machines or users, it is recommended that you use this storage type when creating new objects.
WEB_STORAGE_DOMAIN Local domain storage. Objects stored using this storage type are only available to users in the same local domain, as defined by the domain name or workgroup name assigned to the local system. If the domain or workgroup name changes, objects previously stored using this storage type will not be available to the application.
WEB_STORAGE_MACHINE Local machine storage. Objects stored using this storage type are only available to users on the same local machine. The local machine is identified by unique characteristics of the system, including the boot volume GUID. Objects previously stored using this storage type will not be available on that system if the boot disk is reformatted.
WEB_STORAGE_USER Current user storage. Objects stored using this storage type are only available to the current user logged in on the local machine. The user identifier is based on the Windows user SID that is assigned when the user account is created. If the user account is deleted, the objects previously stored using this storage type will not be available to the application.
dwAttributes
An unsigned integer that specifies the attributes associated with the storage object. This value can be a combination of one or more of the following bit flags using a bitwise OR operation:
Value Description
WEB_OBJECT_DEFAULT Default object attributes. This value is used to indicate the object can be modified, or that the attributes for a previously existing object should not be changed.
WEB_OBJECT_NORMAL A normal object that can be read and modified by the application. This is the default attribute for new objects that are created by the application.
WEB_OBJECT_READONLY A read-only object that can only be read by the application. Attempts to modify or replace the contents of the object will fail. Read-only objects can be deleted.
WEB_OBJECT_HIDDEN A hidden object. Objects with this attribute are not returned when enumerated using the WebEnumObjects function. The object can only be accessed directly when specifying its label.
dwReserved
An unsigned integer value that is reserved for future use. This value should always be zero.
dwTimeout
An unsigned integer value that specifies a timeout period in seconds. If this value is zero, a default timeout period will be used.
lpObject
A pointer to a WEB_STORAGE_OBJECT structure that will contain additional information about the object that has been downloaded. This parameter may be NULL if the information is not required.
lpEventProc
Specifies the procedure-instance address of the application defined callback function. For more information about the callback function, see the description of the WebEventProc callback function. If this parameter is NULL, no callback function will be invoked during the data transfer.
dwParam
A user-defined integer value that is passed to the callback function specified by lpEventProc. If the application targets the x86 (32-bit) platform, this parameter must be a 32-bit unsigned integer. If the application targets the x64 (64-bit) platform, this parameter must be a 64-bit unsigned integer.

Return Value

If the function succeeds, the return value is non-zero. If the function fails, the return value is zero. To get extended error information, call WebGetLastError.

Remarks

The WebUploadFileEx function uploads the contents of a local file and either creates a new storage object, or replaces an object if one already exists with the same label. The WebUploadFile function provides a simpler interface that defaults to uploading an object to the global storage container.

If the label identifies an object that already exists in the container, and that object was created with the WEB_OBJECT_READONLY attribute, this function will fail. To replace a read-only object, the application must explicitly move, rename or delete the existing object.

Unlike the WebPutFile and WebPutFileEx functions, it is not required that you open a storage container using the WebOpenStorage function prior to calling WebUploadFileEx.

Additional metadata about the object will be returned in the WEB_STORAGE_OBJECT structure provided by the caller, such as the date and time the object was created, the content type and the SHA-256 hash of the object contents.

If you are uploading a large file and want your application to receive progress updates during the data transfer, provide a pointer to a callback function as the lpEventProc parameter. That function will receive event notifications as the data is being uploaded.

Example

WEB_STORAGE_OBJECT webObject;

// Upload a local file to the global storage container
if (WebUploadFileEx(lpszLocalFile,
                    lpszObjectLabel,
                    lpszAppId,
                    WEB_STORAGE_GLOBAL,
                    WEB_OBJECT_DEFAULT,
                    0,
                    &webObject,
                    NULL, 0))
{
    // The object was uploaded, display the metadata
    _tprintf(_T("Object:  %s\n"), webObject.szObjectId);
    _tprintf(_T("Label:   %s\n"), webObject.szLabel);
    _tprintf(_T("Size:    %lu\n"), webObject.dwObjectSize);
    _tprintf(_T("Digest:  %s\n"), webObject.szDigest);
    _tprintf(_T("Content: %s\n"), webObject.szContent);
}
else
{
    // The object could not be uploaded, display the error
    TCHAR szError[128];

    WebGetErrorString(WebGetLastError(), szError, 128);    
    _tprintf(_T("Unable to upload \"%s\" (%s)\n"), lpszLocalFile, szError);
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cswebv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also