本文整理汇总了C++中FilePath::mimeContentType方法的典型用法代码示例。如果您正苦于以下问题:C++ FilePath::mimeContentType方法的具体用法?C++ FilePath::mimeContentType怎么用?C++ FilePath::mimeContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilePath
的用法示例。
在下文中一共展示了FilePath::mimeContentType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
std::string Base64ImageFilter::toBase64Image(const boost::cmatch& match)
{
// extract image reference
std::string imgRef = match[3];
// see if this is an image within the base directory. if it is then
// base64 encode it
FilePath imagePath = basePath_.childPath(imgRef);
if (imagePath.exists() &&
boost::algorithm::starts_with(imagePath.mimeContentType(), "image/"))
{
std::string imageBase64;
Error error = core::base64::encode(imagePath, &imageBase64);
if (!error)
{
imgRef = "data:" + imagePath.mimeContentType() + ";base64,";
imgRef.append(imageBase64);
}
else
{
LOG_ERROR(error);
}
}
// return the filtered result
return match[1] + match[2] + imgRef + match[4];
}
示例2: handleContentRequest
void handleContentRequest(const http::Request& request, http::Response* pResponse)
{
// get content file info
std::string title;
FilePath contentFilePath;
Error error = contentFileInfo(request.uri(), &title, &contentFilePath);
if (error)
{
pResponse->setError(error);
return;
}
// set private cache forever headers
pResponse->setPrivateCacheForeverHeaders();
// set file
pResponse->setFile(contentFilePath, request);
bool isUtf8 = true;
if (boost::algorithm::starts_with(contentFilePath.mimeContentType(), "text/"))
{
// If the content looks like valid UTF-8, assume it is. Otherwise, assume
// it's the system encoding.
std::string contents;
error = core::readStringFromFile(contentFilePath, &contents);
if (!error)
{
for (std::string::iterator pos = contents.begin(); pos != contents.end(); )
{
error = string_utils::utf8Advance(pos, 1, contents.end(), &pos);
if (error)
{
isUtf8 = false;
break;
}
}
}
}
// reset content-type with charset
pResponse->setContentType(contentFilePath.mimeContentType() +
std::string("; charset=") +
(isUtf8 ? "UTF-8" : ::locale2charset(NULL)));
// set title header
pResponse->setHeader("Title", title);
}
示例3: iconData
// determines the icon data; this could be either a path on disk (if we have
// a suitable icon locally), base64-encoded icon data (if the icon is embedded
// in an R package), or nothing (if we cannot determine an icon at all)
std::string iconData(const std::string& iconGroup,
const std::string& iconName,
const std::string& iconPath)
{
if (iconPath.empty())
{
// convert the icon name into the format of our shipped icons, which is
// all lowercase with no whitespace (e.g. "SQL Server" => "sqlserver.png")
std::string iconFilename(string_utils::toLower(iconName));
iconFilename = boost::regex_replace(iconFilename,
boost::regex("\\s"), "") + ".png";
// the package did not supply an icon; see if there's one baked in
FilePath path = options().rResourcesPath().childPath("connections")
.childPath(iconGroup)
.childPath(iconFilename);
if (path.exists())
return std::string("connections/") + iconGroup + "/" + iconFilename;
if (iconGroup == "drivers")
return std::string("connections/drivers/odbc.png");
// didn't find anything
return std::string();
}
// expand the path
FilePath icon = module_context::resolveAliasedPath(iconPath);
std::string iconData;
// ensure that the icon file exists and is a small GIF, JPG, or PNG image
if (icon.exists() && icon.size() < kMaxIconSize &&
(icon.hasExtensionLowerCase(".gif") ||
icon.hasExtensionLowerCase(".png") ||
icon.hasExtensionLowerCase(".jpg") ||
icon.hasExtensionLowerCase(".jpeg")))
{
Error error = base64::encode(icon, &iconData);
if (error)
LOG_ERROR(error);
else
{
iconData = "data:" + icon.mimeContentType("image/png") +
";base64," + iconData;
}
}
return iconData;
}
示例4: setFile
void setFile(const FilePath& filePath,
const Request& request,
const Filter& filter)
{
// ensure that the file exists
if (!filePath.exists())
{
setError(http::status::NotFound, request.uri() + " not found");
return;
}
// set content type
setContentType(filePath.mimeContentType());
// gzip if possible
if (request.acceptsEncoding(kGzipEncoding))
setContentEncoding(kGzipEncoding);
// set body from file
Error error = setBody(filePath, filter);
if (error)
setError(status::InternalServerError, error.code().message());
}