Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
c5cea2ab
提交
c5cea2ab
authored
9月 16, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
http post files
上级
f6d6b844
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
209 行增加
和
6 行删除
+209
-6
evslicer.cpp
opencv-motion-detect/evslicer.cpp
+8
-6
postfile.cpp
opencv-motion-detect/postfile.cpp
+67
-0
postfile.h
opencv-motion-detect/postfile.h
+17
-0
test_http_stream_client.cpp
opencv-motion-detect/test_http_stream_client.cpp
+117
-0
没有找到文件。
opencv-motion-detect/evslicer.cpp
浏览文件 @
c5cea2ab
...
@@ -64,20 +64,22 @@ private:
...
@@ -64,20 +64,22 @@ private:
int
ret
=
0
;
int
ret
=
0
;
string
peerId
,
meta
;
string
peerId
,
meta
;
json
data
;
json
data
;
string
msg
;
for
(
auto
&
b
:
v
)
{
msg
+=
body2str
(
b
)
+
";"
;
}
if
(
v
.
size
()
==
3
)
{
if
(
v
.
size
()
==
3
)
{
try
{
try
{
peerId
=
body2str
(
v
[
0
]);
peerId
=
body2str
(
v
[
0
]);
meta
=
json
::
parse
(
body2str
(
v
[
1
]))[
"type"
];
meta
=
json
::
parse
(
body2str
(
v
[
1
]))[
"type"
];
data
=
json
::
parse
(
body2str
(
v
[
2
]));
data
=
json
::
parse
(
body2str
(
v
[
2
]));
spdlog
::
info
(
"evslicer {} received msg from {}, type = {}, data = {}"
,
selfId
,
meta
,
data
.
dump
());
spdlog
::
info
(
"evslicer {} received msg from {}, type = {}, data = {}"
,
selfId
,
peerId
,
meta
,
data
.
dump
());
}
catch
(
exception
&
e
){
}
catch
(
exception
&
e
){
spdlog
::
error
(
"evslicer {} failed to process msg:{}"
,
body2str
(
v
[
1
]),
body2str
(
v
[
2
])
);
spdlog
::
error
(
"evslicer {} failed to process msg:{}"
,
selfId
,
msg
);
}
}
}
else
{
}
else
{
string
msg
;
for
(
auto
&
b
:
v
)
{
msg
+=
body2str
(
b
)
+
";"
;
}
spdlog
::
error
(
"evslicer {} get invalid msg with size {}: {}"
,
selfId
,
v
.
size
(),
msg
);
spdlog
::
error
(
"evslicer {} get invalid msg with size {}: {}"
,
selfId
,
v
.
size
(),
msg
);
}
}
...
...
opencv-motion-detect/postfile.cpp
0 → 100644
浏览文件 @
c5cea2ab
#include "postfile.h"
namespace
netutils
{
static
void
libcurlInit
(){
static
bool
inited
=
false
;
if
(
inited
==
false
)
{
curl_global_init
(
CURL_GLOBAL_ALL
);
inited
=
true
;
}
}
int
postFiles
(
const
char
*
url
,
vector
<
tuple
<
const
char
*
const
,
const
char
*
const
>
>
params
,
vector
<
const
char
*>
fileNames
){
CURL
*
curl
;
CURLcode
res
;
curl_mime
*
form
=
NULL
;
curl_mimepart
*
field
=
NULL
;
struct
curl_slist
*
headerlist
=
NULL
;
libcurlInit
();
curl
=
curl_easy_init
();
if
(
curl
==
NULL
)
{
return
-
1
;
}
/* Create the form */
form
=
curl_mime_init
(
curl
);
/* Fill in the file upload field */
for
(
auto
&
f
:
fileNames
)
{
field
=
curl_mime_addpart
(
form
);
curl_mime_name
(
field
,
"files[]"
);
curl_mime_filedata
(
field
,
f
);
}
string
queryString
;
int
cnt
=
0
;
for
(
auto
&
[
k
,
v
]
:
params
)
{
queryString
+=
(
cnt
==
0
?
string
(
""
)
:
string
(
"&"
))
+
string
(
k
)
+
"="
+
string
(
v
);
cnt
++
;
}
string
_url
=
string
(
url
)
+
"?"
+
queryString
;
/* what URL that receives this POST */
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
_url
.
c_str
());
//curl_easy_setopt(curl, CURLOPT_POSTFIELDS, queryString.c_str());
curl_easy_setopt
(
curl
,
CURLOPT_MIMEPOST
,
form
);
/* Perform the request, res will get the return code */
res
=
curl_easy_perform
(
curl
);
/* Check for errors */
if
(
res
!=
CURLE_OK
){
spdlog
::
error
(
"failed to upload files: {}"
,
curl_easy_strerror
(
res
));
return
-
1
;
}
/* always cleanup */
curl_easy_cleanup
(
curl
);
/* then cleanup the form */
curl_mime_free
(
form
);
/* free slist */
curl_slist_free_all
(
headerlist
);
return
0
;
}
}
opencv-motion-detect/postfile.h
0 → 100644
浏览文件 @
c5cea2ab
#ifndef __EV_POST_FILE_H__
#define __EV_POST_FILE_H__
#include <string>
#include <curl/curl.h>
#include <tuple>
#include <vector>
#include "inc/spdlog/spdlog.h"
namespace
{
int
postFiles
(
const
char
*
url
,
vector
<
tuple
<
const
char
*
const
,
const
char
*
const
>
>
params
,
vector
<
const
char
*>
fileNames
);
}
#endif
\ No newline at end of file
opencv-motion-detect/test_http_stream_client.cpp
0 → 100644
浏览文件 @
c5cea2ab
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
/* <DESC>
* HTTP Multipart formpost with file upload and two additional parts.
* </DESC>
*/
/* Example code that uploads a file name 'foo' to a remote script that accepts
* "HTML form based" (as described in RFC1738) uploads using HTTP POST.
*
* The imaginary form we'll fill in looks like:
*
* <form method="post" enctype="multipart/form-data" action="examplepost.cgi">
* Enter file: <input type="file" name="sendfile" size="40">
* Enter file name: <input type="text" name="filename" size="30">
* <input type="submit" value="send" name="submit">
* </form>
*
* This exact source code has not been verified to work.
*/
#include <string>
#include <curl/curl.h>
#include <tuple>
#include <vector>
#include "inc/spdlog/spdlog.h"
using
namespace
std
;
void
libcurlInit
(){
static
bool
inited
=
false
;
if
(
inited
==
false
)
{
curl_global_init
(
CURL_GLOBAL_ALL
);
inited
=
true
;
}
}
int
postFiles
(
const
char
*
url
,
vector
<
tuple
<
const
char
*
const
,
const
char
*
const
>
>
params
,
vector
<
const
char
*>
fileNames
){
CURL
*
curl
;
CURLcode
res
;
curl_mime
*
form
=
NULL
;
curl_mimepart
*
field
=
NULL
;
struct
curl_slist
*
headerlist
=
NULL
;
libcurlInit
();
curl
=
curl_easy_init
();
if
(
curl
==
NULL
)
{
return
-
1
;
}
/* Create the form */
form
=
curl_mime_init
(
curl
);
/* Fill in the file upload field */
for
(
auto
&
f
:
fileNames
)
{
field
=
curl_mime_addpart
(
form
);
curl_mime_name
(
field
,
"files[]"
);
curl_mime_filedata
(
field
,
f
);
}
string
queryString
;
int
cnt
=
0
;
for
(
auto
&
[
k
,
v
]
:
params
)
{
queryString
+=
(
cnt
==
0
?
string
(
""
)
:
string
(
"&"
))
+
string
(
k
)
+
"="
+
string
(
v
);
cnt
++
;
}
string
_url
=
string
(
url
)
+
"?"
+
queryString
;
/* what URL that receives this POST */
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
_url
.
c_str
());
//curl_easy_setopt(curl, CURLOPT_POSTFIELDS, queryString.c_str());
curl_easy_setopt
(
curl
,
CURLOPT_MIMEPOST
,
form
);
/* Perform the request, res will get the return code */
res
=
curl_easy_perform
(
curl
);
/* Check for errors */
if
(
res
!=
CURLE_OK
){
spdlog
::
error
(
"failed to upload files: {}"
,
curl_easy_strerror
(
res
));
return
-
1
;
}
/* always cleanup */
curl_easy_cleanup
(
curl
);
/* then cleanup the form */
curl_mime_free
(
form
);
/* free slist */
curl_slist_free_all
(
headerlist
);
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
vector
<
tuple
<
const
char
*
const
,
const
char
*
const
>
>
params
=
{{
"startTime"
,
"1568027134"
},{
"endTime"
,
"1568027254"
},{
"cameraId"
,
"1"
},
{
"headOffset"
,
"5"
},{
"tailOffset"
,
"10"
}};
const
char
*
url
=
"http://139.219.142.18:10008/upload/evtvideos/1"
;
vector
<
const
char
*>
fileNames
=
{
"slices/1568027134.mp4"
,
"slices/1568027254.mp4"
};
postFiles
(
url
,
params
,
fileNames
);
return
0
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论