curl-library
Re: Upload image,video using Http POST
Date: Tue, 8 Feb 2011 13:55:48 +0530
Hi All,
Thank you all for your nice help, I am able to upload a video file(*.ts) to
a Media Server.
I have another query, if I break a video file( *.ts) into two parts, can I
do http POST in the required URI?
This code is giving me this error:
* About to connect() to 107.108.161.186 port 52345 (#0)
* Trying 107.108.161.186... * connected
* Connected to 107.108.161.186 (107.108.161.186) port 52345 (#0)
> POST /cd/content?didx=0_id=72 HTTP/1.1
Host: 107.108.161.186:52345
Accept: */*
Content-Length: 1391656
Expect: 100-continue
Content-Type: multipart/form-data;
boundary=----------------------------abaaf8ec2f5f
< HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Content-Length: 0
* Connection #0 to host 107.108.161.186 left intact
* Closing connection #0
* About to connect() to 107.108.161.186 port 52345 (#0)
* Trying 107.108.161.186... * connected
* Connected to 107.108.161.186 (107.108.161.186) port 52345 (#0)
> POST /cd/content?didx=0_id=72 HTTP/1.1
Host: 107.108.161.186:52345
Accept: */*
Content-Length: 1391656
Expect: 100-continue
Content-Type: multipart/form-data;
boundary=----------------------------3d9cef686186
< HTTP/1.1 500 Internal Server Error
< Connection: close
< Content-Length: 0
< Server: DMRND/0.5
<
* Closing connection #0
*CODE*:
char* filePath = "/root/Pictures/test1.ts";
char* readFileBytes(const char *name,int fileLen,FILE* file)
{
char* buffer;
buffer=(char *)malloc(fileLen);
if (!buffer)
{
fprintf(stderr, "Memory error!");
fclose(file);
exit(1);
}
int ret = fread(buffer, 1,fileLen, file);
if(!ret )
{
printf("Empty File \n");
fclose(file);
}
//fclose(file);
return buffer;
}
int GetFileLength(char* name)
{
FILE *filePtr = fopen(name, "rb");
if (!filePtr)
{
fprintf(stderr, "can't open filePtr %s", name);
exit(1);
}
fseek(filePtr, 0, SEEK_END);
int fileLen=ftell(filePtr);
fseek(filePtr, 0, SEEK_SET);
fclose(filePtr);
return fileLen;
}
FILE * moveFilePtrTo(FILE *filePtr,int nPos)
{
fseek(filePtr, nPos, SEEK_SET);
return filePtr;
}
void postUsingCurl(char* bufPtr,int fileLen)
{
CURL *curl;
CURLcode res;
struct curl_httppost *formpost=NULL;
struct curl_httppost *lastptr=NULL;
struct curl_slist *headers=NULL;
headers = curl_slist_append(headers, "Content-Type:
multipart/form-data");
curl_global_init(CURL_GLOBAL_ALL);
curl_formadd(&formpost, &lastptr,
CURLFORM_COPYNAME, "F1",
CURLFORM_BUFFER, "data",
CURLFORM_BUFFERPTR, bufPtr ,
CURLFORM_BUFFERLENGTH, fileLen,
CURLFORM_END);
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_URL, "
http://107.108.161.186:52345/cd/content?didx=0_id=72");
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_formfree(formpost);
}
}
int main()
{
int Length = GetFileLength(filePath);
FILE *filePtr = fopen(filePath, "rb");
int lenFlag;
for(int i = 0 ; i < 2 ; i ++)
{
char* buf = readFileBytes(filePath,Length/2,filePtr);
postUsingCurl(buf,Length/2);
filePtr = moveFilePtrTo(filePtr,Length/2);
}
fclose(filePtr);
return 0;
}
Warm regards,
Yogesh
On Tue, Feb 1, 2011 at 2:37 PM, <curl-library-request_at_cool.haxx.se> wrote:
> Send curl-library mailing list submissions to
> curl-library_at_cool.haxx.se
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-library
> or, via email, send a message with subject or body 'help' to
> curl-library-request_at_cool.haxx.se
>
> You can reach the person managing the list at
> curl-library-owner_at_cool.haxx.se
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of curl-library digest..."
>
>
> Today's Topics:
>
> 1. Re: [GitHub] Provide support for CURLOPT_TIMECONDITION on
> file:// schema transfers [bagder/curl GH-6] (fwd) (Kamil Dudka)
> 2. Re: [GitHub] Provide support for CURLOPT_TIMECONDITION on
> file:// schema transfers [bagder/curl GH-6] (fwd) (Daniel Stenberg)
> 3. Re: [GitHub] Provide support for CURLOPT_TIMECONDITION on
> file:// schema transfers [bagder/curl GH-6] (fwd) (Kamil Dudka)
> 4. Re: SFTP file info and state machine (John Utz)
> 5. Re: SFTP file info and state machine (John Utz)
> 6. libcurl multi interface interleave GET and POST calls
> (Andrei Ionescu)
> 7. libcurl and lwip (Prashant R)
> 8. Re: libcurl and lwip (Daniel Stenberg)
> 9. Re: CURLOPT_MAX_RECV_SPEED_LARGE and multi_socket_action
> (with patch) (Daniel Stenberg)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Mon, 31 Jan 2011 14:57:23 +0100
> From: Kamil Dudka <kdudka_at_redhat.com>
> To: Daniel Stenberg <daniel_at_haxx.se>
> Cc: libcurl development <curl-library_at_cool.haxx.se>
> Subject: Re: [GitHub] Provide support for CURLOPT_TIMECONDITION on
> file:// schema transfers [bagder/curl GH-6] (fwd)
> Message-ID: <4D46BFC3.3000206_at_redhat.com>
> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
>
> On 01/30/2011 12:50 AM, Daniel Stenberg wrote:
> > FYI,
> >
> > As this isn't really to me personally...
> >
> Hi Daniel,
>
> are you fine with the attached patches?
>
> Kamil
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: 0001-transfer-add-Curl_meets_timecondition.patch
> Type: text/x-patch
> Size: 3705 bytes
> Desc: not available
> URL: <
> http://cool.haxx.se/pipermail/curl-library/attachments/20110131/95d76aac/attachment-0002.bin
> >
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: 0002-file-add-support-for-CURLOPT_TIMECONDITION.patch
> Type: text/x-patch
> Size: 2664 bytes
> Desc: not available
> URL: <
> http://cool.haxx.se/pipermail/curl-library/attachments/20110131/95d76aac/attachment-0003.bin
> >
>
> ------------------------------
>
> Message: 2
> Date: Mon, 31 Jan 2011 14:56:54 +0100 (CET)
> From: Daniel Stenberg <daniel_at_haxx.se>
> To: Kamil Dudka <kdudka_at_redhat.com>
> Cc: libcurl development <curl-library_at_cool.haxx.se>
> Subject: Re: [GitHub] Provide support for CURLOPT_TIMECONDITION on
> file:// schema transfers [bagder/curl GH-6] (fwd)
> Message-ID: <alpine.DEB.2.00.1101311456370.28922_at_tvnag.unkk.fr>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
>
> On Mon, 31 Jan 2011, Kamil Dudka wrote:
>
> > are you fine with the attached patches?
>
> They look great!
>
> --
>
> / daniel.haxx.se
>
>
> ------------------------------
>
> Message: 3
> Date: Mon, 31 Jan 2011 15:21:58 +0100
> From: Kamil Dudka <kdudka_at_redhat.com>
> To: Dave Reisner <d_at_falconindy.com>
> Cc: libcurl development <curl-library_at_cool.haxx.se>
> Subject: Re: [GitHub] Provide support for CURLOPT_TIMECONDITION on
> file:// schema transfers [bagder/curl GH-6] (fwd)
> Message-ID: <4D46C586.8020303_at_redhat.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 01/31/2011 02:56 PM, Daniel Stenberg wrote:
> > On Mon, 31 Jan 2011, Kamil Dudka wrote:
> >
> >> are you fine with the attached patches?
> >
> > They look great!
> >
>
> Oops, I forgot to CC Dave on the previous mail. Dave, thanks for your
> contribution. Next time please avoid using git hashes that are not yet
> upstream in your commit logs. They mostly become invalid as soon as we
> push them.
>
> Kamil
>
>
> ------------------------------
>
> Message: 4
> Date: Mon, 31 Jan 2011 18:32:01 -0500 (EST)
> From: John Utz <john_at_utzweb.net>
> To: libcurl development <curl-library_at_cool.haxx.se>
> Subject: Re: SFTP file info and state machine
> Message-ID:
> <22394169.2949.1296516720971.JavaMail.root_at_mail.grokthis.net>
> Content-Type: text/plain; charset=utf-8
>
>
>
> ----- Original Message -----
> > On Fri, 28 Jan 2011, John Utz wrote:
> >
> > > It seems to me that this job should be done only in the state
> > >
> > > "SSH_SFTP_QUOTE_STAT"
> > >
> > > instead of being spread between SSH_SFTP_QUOTE_STAT and
> > > SSH_SCP_TRANS_INIT
> >
> > No, the QUOTE states are only used for quote commands and the
> > SSH_SFTP_QUOTE_STAT in specific is only used of a stat-using quote
> > command is
> > used.
>
> Thankyou for explaining that.
>
> > When doing SFTP download, the libssh2_sftp_stat_ex() command is
> > already used
> > in the SSH_SFTP_DOWNLOAD_STAT state and I figure you should be able to
> > set the
> > information properly after that point.
>
> if you are only checking fileinfo, you dont make it to
> SSH_SFTP_DOWNLOAD_STAT, you only make it to SSH_SFTP_TRANS_INIT. There are
> several edges inside of the SSH_SFTP_TRANS_INIT case statement and
> SSH_SFTP_DOWNLOAD_STAT is but one of them.
>
> That explains why Sr. Mele chose to insert the code where he did. :-)
>
> I agree that the use of libssh2_sftp_stat_ex() is a good(best?) choice
> getting the file data, but it would be gratuitously consumptive to call it
> twice in the download case.
>
> Would it not be reasonable to add the libssh2_sftp_stat_ex() call to
> SSH_SFTP_TRANS_INIT and delete it from SSH_SFTP_DOWNLOAD_STAT?
>
> commentary appreciated as always!
>
> tnx!
>
> johnu
>
>
> ------------------------------
>
> Message: 5
> Date: Mon, 31 Jan 2011 18:40:26 -0500 (EST)
> From: John Utz <john_at_utzweb.net>
> To: libcurl development <curl-library_at_cool.haxx.se>
> Subject: Re: SFTP file info and state machine
> Message-ID:
> <7649593.2955.1296517226095.JavaMail.root_at_mail.grokthis.net>
> Content-Type: text/plain; charset=utf-8
>
> responding to self cause i just realized a few problems with my cunning
> plan....
>
> ----- Original Message -----
> > ----- Original Message -----
> > > On Fri, 28 Jan 2011, John Utz wrote:
> > >
> > > > It seems to me that this job should be done only in the state
> > > >
> > > > "SSH_SFTP_QUOTE_STAT"
> > > >
> > > > instead of being spread between SSH_SFTP_QUOTE_STAT and
> > > > SSH_SCP_TRANS_INIT
> > >
> > > No, the QUOTE states are only used for quote commands and the
> > > SSH_SFTP_QUOTE_STAT in specific is only used of a stat-using quote
> > > command is
> > > used.
> >
> > Thankyou for explaining that.
> >
> > > When doing SFTP download, the libssh2_sftp_stat_ex() command is
> > > already used
> > > in the SSH_SFTP_DOWNLOAD_STAT state and I figure you should be able
> > > to
> > > set the
> > > information properly after that point.
> >
> > if you are only checking fileinfo, you dont make it to
> > SSH_SFTP_DOWNLOAD_STAT, you only make it to SSH_SFTP_TRANS_INIT. There
> > are several edges inside of the SSH_SFTP_TRANS_INIT case statement and
> > SSH_SFTP_DOWNLOAD_STAT is but one of them.
> >
> > That explains why Sr. Mele chose to insert the code where he did. :-)
> >
> > I agree that the use of libssh2_sftp_stat_ex() is a good(best?) choice
> > getting the file data, but it would be gratuitously consumptive to
> > call it twice in the download case.
> >
> > Would it not be reasonable to add the libssh2_sftp_stat_ex() call to
> > SSH_SFTP_TRANS_INIT and delete it from SSH_SFTP_DOWNLOAD_STAT?
>
> dang it, the problem with this is that the 'size' variable is local to the
> SSH_SFTP_DOWNLOAD_STAT case and said case performs a non-trivial amount of
> cognition about the size of the file prior to actually performing the
> download.
>
> i see no problem with that processing remaining where it is since it's the
> only state that cares about it, but that means that the 'size' variable
> would need to be scoped at the function level instead of the case statement
> level.
>
> A quick survey of the code doesnt show any conflicts with doing that.
>
> > commentary appreciated as always!
> >
> > tnx!
> >
> > johnu
>
>
> ------------------------------
>
> Message: 6
> Date: Mon, 31 Jan 2011 19:17:59 -0500
> From: Andrei Ionescu <andrei.ionescu_at_gmail.com>
> To: curl-library_at_cool.haxx.se
> Subject: libcurl multi interface interleave GET and POST calls
> Message-ID:
> <AANLkTim9VKx9qcsQbZyO=sf=EEuYWY1b636kv9=qPtnU_at_mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi,
>
> I just started using libcurl since I need to talk to a HTTP server and
> I figure it would be faster to use libcurl rather than write my own
> HTTP layer on top of TCP. Previously I've been using just straight TCP
> for communication between internal components where the sent data was
> HTTP-ish, where the full protocol wasn't supported and I really didn't
> need to be up to spec since I didn't need to communicate with any
> external servers. My question here may be a very basic HTTP/libcurl
> question but here is my situation:
> - the client connects to the server and it can send data to it by issuing a
> POST
> - the server will send data to the client in a POST, but only if the
> client performed a GET to the server (if no data is available then it
> will not respond immediately)
>
> Can I use a single handle and pass it to libcurl's multi interface to
> do all the above? The problem that I have is that I can't see a way of
> sending both GETs and POSTs on a single handle without doing a
> curl_easy_setopt on the handle which is now owned by the multi handle.
> Am I stuck with having to open two connections to the server or am I
> missing something obvious in libcurl?
>
> Thanks,
> Andrei.
>
>
> ------------------------------
>
> Message: 7
> Date: Mon, 31 Jan 2011 19:07:35 -0800
> From: Prashant R <ramapra_at_gmail.com>
> To: curl-library_at_cool.haxx.se
> Subject: libcurl and lwip
> Message-ID:
> <AANLkTimTzKHHqNArYvYFLejyot=QFqNWJnZQqKo7T1f6_at_mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Currently I am interested in using libcurl specifically for http and https
> .
> The intent is to port libcurl on an embedded platform .
>
> I am wondering if there are any options to be able to configure various
> options for libcurl .
>
>
> Also I am looking to use lwip's tcp/ip stack in libcurl . Where do I
> specify
> this linkage ?
>
> Thanks !
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://cool.haxx.se/pipermail/curl-library/attachments/20110131/d16337be/attachment-0001.htm
> >
>
> ------------------------------
>
> Message: 8
> Date: Tue, 1 Feb 2011 10:05:31 +0100 (CET)
> From: Daniel Stenberg <daniel_at_haxx.se>
> To: libcurl development <curl-library_at_cool.haxx.se>
> Subject: Re: libcurl and lwip
> Message-ID: <alpine.DEB.2.00.1102011003400.10046_at_tvnag.unkk.fr>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
>
> On Mon, 31 Jan 2011, Prashant R wrote:
>
> > I am wondering if there are any options to be able to configure various
> > options for libcurl .
>
> ./configure --help shows most of them. The docs/INSTALL file descusses a
> bunch
> of them.
>
> > Also I am looking to use lwip's tcp/ip stack in libcurl . Where do I
> specify
> > this linkage ?
>
> libcurl isn't linked to use any particular tcp/ip stack. It uses
> socket/POSIX
> functions and you're free to provide them using any ip stack you please.
>
> --
>
> / daniel.haxx.se
>
>
> ------------------------------
>
> Message: 9
> Date: Tue, 1 Feb 2011 10:07:27 +0100 (CET)
> From: Daniel Stenberg <daniel_at_haxx.se>
> To: libcurl development <curl-library_at_cool.haxx.se>
> Subject: Re: CURLOPT_MAX_RECV_SPEED_LARGE and multi_socket_action
> (with patch)
> Message-ID: <alpine.DEB.2.00.1102011006360.10046_at_tvnag.unkk.fr>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
>
> On Sun, 30 Jan 2011, Nicholas Maniscalco wrote:
>
> > It appears that multi_runsingle may be leaving sockets in
> > CURLM_STATE_TOOFAST for too long because it is working off of outdated
> > progress data. Attached is a patch that calls Curl_pgrsUpdate just
> inside
> > the TOOFAST case (multi_toofast_update_progress.patch). With this patch,
> I
> > observe a nice smooth rate-limited transfer (see
> hiperfifo_output_good.txt).
> >
> > Is there a better approach to fixing this?
>
> Thanks a lot. I think this is a good and cheap fix!
>
> --
>
> / daniel.haxx.se
>
>
> ------------------------------
>
> _______________________________________________
> curl-library mailing list
> curl-library_at_cool.haxx.se
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-library
>
>
> End of curl-library Digest, Vol 66, Issue 1
> *******************************************
>
-- Warm regards, Yogeshwar http://invinciblev1.blogspot.com/
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-02-08