-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如果构建一个httpserver用于文件下载 #58
Comments
目前不能自动搜索和匹配文件,需要手动根据传入的数据匹配对应的文件,然后调用replyFile接口返回 |
你好,
感谢你的回信。传入的数据匹配方式是否有例程可以参考一下。
张伟
***@***.***
13801276625
电子名片新出VIP模板啦,快来体验>>
扫一扫,
快速添加名片到手机
…--------------------------------------------------------------------------------
------------------ 原始邮件 ------------------
发件人: Jason ***@***.***>
发送时间: 2023-04-13 10:11:37
收件人:188080501/JQHttpServer ***@***.***>
抄送:张伟 ***@***.***>,Author ***@***.***>
主题: Re: [188080501/JQHttpServer] 如果构建一个httpserver用于文件下载 (Issue #58)
目前不能自动搜索和匹配文件,需要手动根据传入的数据匹配对应的文件,然后调用replyFile接口返回
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
可以参考下这个
|
谢谢,文件服务已经可以了
张伟
***@***.***
13801276625
电子名片新出VIP模板啦,快来体验>>
扫一扫,
快速添加名片到手机
…--------------------------------------------------------------------------------
------------------ 原始邮件 ------------------
发件人: Jason ***@***.***>
发送时间: 2023-04-14 14:40:38
收件人:188080501/JQHttpServer ***@***.***>
抄送:张伟 ***@***.***>,Author ***@***.***>
主题: Re: [188080501/JQHttpServer] 如果构建一个httpserver用于文件下载 (Issue #58)
void onRequestAccepted(const QPointer< JQHttpServer::Session > &session)
{
if ( session->requestMethod() != "GET" )
{
session->replyText( "unsupport request method", 404 )
return
}
auto relativeFilePath = session->requestUrlPath()
if ( relativeFilePath.isEmpty() )
{
session->replyText( "path is empty", 404 )
return
}
if ( relativeFilePath.isEmpty() ||
relativeFilePath.startsWith( "." ) ||
!relativeFilePath.startsWith( "/" ) ||
relativeFilePath.contains( ".." ) ||
relativeFilePath.contains( "\\" ) ||
( relativeFilePath.size() > 1000 ) )
{
session->replyText( "path error", 404 )
return
}
QFileInfo fileIfno( QString( "%1%2" ).arg( webPath_, relativeFilePath ) )
if ( !fileIfno.exists() )
{
session->replyText( "file not exists", 404 )
return
}
if ( fileIfno.suffix().toLower() == "html" )
{
QFile file( fileIfno.filePath() )
file.open( QIODevice::ReadOnly )
const auto data = file.readAll()
session->replyBytes( data, "text/htmlcharset=UTF-8" )
}
else if ( QSet< QString >( { "png", "jpg", "jpeg", "ico", "bmp" } ).contains( fileIfno.suffix().toLower() ) )
{
session->replyImage( fileIfno.filePath() )
}
else
{
session->replyFile( fileIfno.filePath() )
}
}
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
编译过了,但是不知道如何添加被能被下载的指定文件
The text was updated successfully, but these errors were encountered: