本文整理汇总了C++中http::Request::uploadedFile方法的典型用法代码示例。如果您正苦于以下问题:C++ Request::uploadedFile方法的具体用法?C++ Request::uploadedFile怎么用?C++ Request::uploadedFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http::Request
的用法示例。
在下文中一共展示了Request::uploadedFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleFileUploadRequest
void handleFileUploadRequest(const http::Request& request,
http::Response* pResponse)
{
// response content type must always be text/html to be handled
// properly by the browser/gwt on the client side
pResponse->setContentType("text/html");
// get fields
const http::File& file = request.uploadedFile("file");
std::string targetDirectory = request.formFieldValue("targetDirectory");
// first validate that we got the required fields
if (file.name.empty() || targetDirectory.empty())
{
json::setJsonRpcError(json::errc::ParamInvalid, pResponse);
return;
}
// now validate the file
if ( !validateUploadedFile(file, pResponse) )
return ;
// form destination path
FilePath destDir = module_context::resolveAliasedPath(targetDirectory);
FilePath destPath = destDir.childPath(file.name);
// establish whether this is a zip file and create appropriate temp file path
bool isZip = destPath.extensionLowerCase() == ".zip";
FilePath tempFilePath = module_context::tempFile("upload",
isZip ? "zip" : "bin");
// attempt to write the temp file
Error saveError = core::writeStringToFile(tempFilePath, file.contents);
if (saveError)
{
LOG_ERROR(saveError);
json::setJsonRpcError(saveError, pResponse);
return;
}
// detect any potential overwrites
json::Array overwritesJson;
if (isZip)
{
Error error = detectZipFileOverwrites(tempFilePath,
destDir,
&overwritesJson);
if (error)
{
LOG_ERROR(error);
json::setJsonRpcError(error, pResponse);
return;
}
}
else
{
if (destPath.exists())
overwritesJson.push_back(module_context::createFileSystemItem(destPath));
}
// set the upload information as the result
json::Object uploadTokenJson;
uploadTokenJson[kUploadFilename] = file.name;
uploadTokenJson[kUploadedTempFile] = tempFilePath.absolutePath();
uploadTokenJson[kUploadTargetDirectory] = destDir.absolutePath();
json::Object uploadJson;
uploadJson["token"] = uploadTokenJson;
uploadJson["overwrites"] = overwritesJson;
json::setJsonRpcResult(uploadJson, pResponse);
}