如何在yy上传视频文件

3724人阅读
UNIX环境高级编程(15)
c语言(24)
UNIX网络编程(1)
提交表单方式
/***************************************************************************
___| | | |
/ __| | | | |_) | |
| (__| |_| |
\___|\___/|_| \_\_____|
* Copyright (C) 1998 - 2015, 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 http://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.
***************************************************************************/
* using the multi interface to do a multipart formpost without blocking
int main(void)
CURLM *multi_
int still_
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headerlist=NULL;
static const char buf[] = "Expect:";
/* Fill in the file upload field. This makes libcurl load data from
the given file name when curl_easy_perform() is called. */
curl_formadd(&formpost,
CURLFORM_COPYNAME, "sendfile",
CURLFORM_FILE, "postit2.c",
CURLFORM_END);
/* Fill in the filename field */
curl_formadd(&formpost,
CURLFORM_COPYNAME, "filename",
CURLFORM_COPYCONTENTS, "postit2.c",
CURLFORM_END);
/* Fill in the submit field too, even if this is rarely needed */
curl_formadd(&formpost,
CURLFORM_COPYNAME, "submit",
CURLFORM_COPYCONTENTS, "send",
CURLFORM_END);
curl = curl_easy_init();
multi_handle = curl_multi_init();
/* initialize custom header list (stating that Expect: 100-continue is not
headerlist = curl_slist_append(headerlist, buf);
if(curl && multi_handle) {
/* what URL that receives this POST */
curl_easy_setopt(curl, CURLOPT_URL, "/upload.cgi");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_multi_add_handle(multi_handle, curl);
curl_multi_perform(multi_handle, &still_running);
/* select() return code */
CURLM /* curl_multi_fdset() return code */
int maxfd = -1;
long curl_timeo = -1;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
/* set a suitable timeout to play around with */
timeout.tv_sec = 1;
timeout.tv_usec = 0;
curl_multi_timeout(multi_handle, &curl_timeo);
if(curl_timeo &= 0) {
timeout.tv_sec = curl_timeo / 1000;
if(timeout.tv_sec & 1)
timeout.tv_sec = 1;
timeout.tv_usec = (curl_timeo % 1000) * 1000;
/* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
if(mc != CURLM_OK)
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
/* On success the value of maxfd is guaranteed to be &= -1. We call
select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
to sleep 100ms, which is the minimum suggested value in the
curl_multi_fdset() doc. */
if(maxfd == -1) {
Sleep(100);
/* Portable sleep for platforms other than Windows. */
struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
rc = select(0, NULL, NULL, NULL, &wait);
/* Note that on some platforms 'timeout' may be modified by select().
If you need access to the original value save a copy beforehand. */
rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
switch(rc) {
/* select error */
/* timeout or readable/writable sockets */
printf("perform!\n");
curl_multi_perform(multi_handle, &still_running);
printf("running: %d!\n", still_running);
} while(still_running);
curl_multi_cleanup(multi_handle);
/* always cleanup */
curl_easy_cleanup(curl);
/* then cleanup the formpost chain */
curl_formfree(formpost);
/* free slist */
curl_slist_free_all (headerlist);
#include &fcntl.h&
#include &sys/stat.h&
#include &curl/curl.h&
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
retcode = fread(ptr, size, nmemb, stream);
nread = (curl_off_t)
fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
" bytes from file\n", nread);
int main(int argc, char **argv)
FILE * hd_
struct stat file_
if(argc & 3)
file= argv[1];
url = argv[2];
stat(file, &file_info);
hd_src = fopen(file, "rb");
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_PUT, 1L);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
(curl_off_t)file_info.st_size);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
fclose(hd_src);
curl_global_cleanup();
直接post二进制流
int dsdAAASetIcon(struct dsdAAA *dsdAAAObject, char *imagePath,
dsdAAACallBack callback, char *userBuf)
char url[512] = { 0 };
char userp[1024];
int res = AAA_SUCCESS;
char *postContent = NULL;
struct curl_slist *slist = NULL;
struct stat fileI
if (imagePath == NULL || (dsdAAAObject == NULL)
|| (callback == NULL) || (userBuf == NULL)) {
dsdl_err("argument can't be empty\n");
return -AAA_ERROR;
file = fopen(imagePath, "rb");
if (file == NULL) {
dsdl_err("open file failed\n");
return -AAA_ERROR;
stat(imagePath, &fileInfo);
long fileSize = fileInfo.st_size;
dsdl_debug("文件大小是 = %ld\n", fileSize);
postContent = (char*)malloc(fileSize);
if (postContent == NULL) {
dsdl_err("malloc failed\n");
return -AAA_ERROR;
int readCount = fread(postContent, 1, fileSize, file);
if (readCount != fileSize) {
dsdl_err("read file failed\n");
fclose(file);
free(postContent);
return -AAA_ERROR;
snprintf(url, sizeof(url), "%s/update_portrait?token=%s",
dsdAAAObject-&serverUrl, dsdAAAObject-&token);
dsdl_debug("url = %s\n", url);
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "curl/7.38.0");
slist = curl_slist_append(slist, "Content-Type: image/png");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, userp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlCallback);
dsdl_debug("dsdAAAObject-&cookie = %s\n", dsdAAAObject-&cookie);
curl_easy_setopt(curl, CURLOPT_COOKIELIST, dsdAAAObject-&cookie);
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_READDATA, file);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, fileSize);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postContent);
dsdl_debug("start send file to server\n");
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
dsdl_err("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
res = -AAA_ERROR;
curl_easy_cleanup(curl);
callback(userp, userBuf);
fclose(file);
free(postContent);
curl_global_cleanup();
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:105229次
积分:2313
积分:2313
排名:第17745名
原创:104篇
转载:24篇
评论:17条
关注我的公众号,学习更多关于Linux开发方面的知识。
感兴趣的朋友可以加入我的QQ群,一起讨论学习,共同进步。
(6)(6)(1)(1)(2)(1)(2)(6)(9)(9)(1)(4)(2)(3)(3)(1)(5)(2)(1)(1)(1)(3)(4)(3)(3)(3)(16)(5)(4)(15)(1)(2)(2)
(window.slotbydup = window.slotbydup || []).push({
id: '4740887',
container: s,
size: '250,250',
display: 'inlay-fix'如何在YY频道的公告栏中插入自己制作的视频文件,并能自动播放?
如何在YY频道的公告栏中插入自己制作的视频文件,并能自动播放?
09-10-28 &
你会制作视频嘛?去56.土豆网,视频网站都可以,你会制作的话就不必多说了,无非是找好图片贴上音乐就行了。制作好视频后去你的歪歪,点击1.右键歪歪频道名称 2.左键点击频道信息 3.点击公告 4.复制你制作视频的网址 5.确定--------就ok了。
请登录后再发表评论!
那个YY积分得上了三千才可以上传~~~
请登录后再发表评论!}

我要回帖

更多关于 yy上传视频 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信