FVSDK_ERROR_CODE FVSDK_CreateFile(FVSDK_Session* pSession, LPCTSTR pszFileName, BOOL bBinary, FVSDK_FILE_SIZE fsResumeLoc);
Opens a file on the server for upload. After a file is successfully created, the file may be written to using FVSDK_WriteFile(). The file cannot be written to and read from at the same time. Use FVSDK_Upload() to upload a file or files in a single step.
This function calls FVSDK_OpenFileRW() with the bRead parameter set to FALSE.
NOTE: Only one file can be open at a time per session.
pSession
A pointer to the FVSDK_Session that is to perform the operation.
pszFileName
The file name or path to create on the server. This NULL terminated string may be either a file name or a full path. If using a file name, the file will be created in the current directory.
bBinary
Set to TRUE to transfer the file using binary (image) mode. Set to FALSE to use ASCII mode.
fsResumeLoc
When starting at the beginning of a file, use 0. When resuming a transfer, use the byte position within the file starting at 0 to (file length - 1). NOTE: Not all severs support the resume capability (the REST command).
FVSDK_YES if the function was successful; FVSDK_NO the file was not created. Error codes can be found in FVSDK_ErrorCodes.h.
CStdioFile File;
FVSDK_Session* pSession;
CString sRemoteName;
// ... upload preparation ...
// get the local file size
FVSDK_FILE_SIZE fsLocalFileSize = File.GetLength();
// create the file to be uploaded on the server
if (FVSDK_CreateFile(pSession, sRemoteName, TRUE, 0) == FVSDK_YES) {
BYTE Buffer[1024];
int nBytes;
FVSDK_FILE_SIZE fsWritten = 0;
// read all of the data from the local file, and write it to the remote file
while ((nBytes = File.Read(Buffer, sizeof(Buffer))) > 0) {
// do the write
if (FVSDK_WriteFile(pSession, Buffer, &nBytes, ((nBytes + fsWritten) >= fsLocalFileSize)) != FVSDK_YES) {
// put up an error message
AfxMessageBox("Unable to write to the remote file", MB_ICONEXCLAMATION);
// get out, we encountered an error while uploading
break;
} // if
// increment the number of bytes written to the file
fsWritten += nBytes;
} // while
// close the remote file
if (FVSDK_CloseFile(pSession) != FVSDK_YES)
AfxMessageBox("Unable to close the remote file", MB_ICONEXCLAMATION);
} // if
else
AfxMessageBox("Unable to create the remote file", MB_ICONEXCLAMATION);
// ... upload cleanup ...