cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: What is the best way to debug this?

From: Igor Korot <ikorot01_at_gmail.com>
Date: Sun, 15 Jul 2012 13:32:07 -0700

Hi, guys,

On Sun, Jul 15, 2012 at 6:04 AM, Lijo Antony <lta_at_one.com> wrote:
> On 07/15/2012 04:34 PM, Gisle Vanem wrote:
>>
>> "Igor Korot" <ikorot01_at_gmail.com> wrote:
>>
>>> Here is my code:
>>>
>>> [code]
>>> struct curl_slist *post = NULL;
>>> char *data;
>>> sprintf( data, "---------------------------%x",
>>> static_cast<unsigned int>( time( NULL ) ) );
>>> post = curl_slist_append( post, "Content-Type: multipart/form-data" );
>>> post = curl_slist_append( post, "Expect: 100-continue" );
>>> post = curl_slist_append( post, "Connection: keep-alive" );
>>> curl_easy_setopt( handle, CURLOPT_READFUNCTION, CWindowPanel::put_data );
>>> curl_easy_setopt( handle, CURLOPT_READDATA, &data );
>>
>>
>> You call sprintf() with a data pointer initialised where? 'data' points to
>> a random location. Strange it doesn't crash. think you should do
>> char data[100];
>> snprintf (data, sizeof(data), "...");
>>
>> And be careful using C++ functions as callbacks.
>>
>
> Just to add, if all you want to do is post some data from a buffer to
> server, you could just use CURLOPT_POSTFIELDS or CURLOPTCOPYPOSTFIELDS ,
> without going for the callbacks. They are documented at
> http://curl.haxx.se/libcurl/c/curl_easy_setopt.html.

Yes, the data variable is of course not NULL. It allocates dynamically
and then deleted.
Also thank you for the tip about CURLOPT_COPYFIELDS. I will look at the docs
for the description.

Now I finally got a hold of the server code. I'm not an expert on this
but hopefully someone here
can tell me if I'm right.

[code]
default.aspx

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>

    <div>
    <form id="Form2" Method="Post" EncType="Multipart/Form-Data" RunAt="Server">

   <%-- The File upload Html control --%>
   Choose Your File To Upload <BR>
   <Input Name="MyFile" id="MyFile" Type="File" RunAt="Server">
   <BR>

   <%-- A button - when clicked the form is submitted and the
            Upload_Click event handler is fired... --%>
   <Input id="Submit1" Type="Submit" Value="Upload"
             RunAt="Server">

    </form> </div>
</body>
</html>

Default.aspx.vb
Imports System.IO

Partial Class _Default

    Inherits System.Web.UI.Page
    Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
        'If Page.IsPostBack Then
        'Grab the file name from its fully qualified path at client
        Dim strFileName As String = MyFile.PostedFile.FileName
        'Response.Write(strFileName)
        ' only the attched file name not its path
        Dim c As String = System.IO.Path.GetFileName(strFileName)

        'Save uploaded file to server at C:\ServerFolder\
        Try
            MyFile.PostedFile.SaveAs("C:\inetpub\wwwroot\TouchAndRead\files\"
+ c)

        Catch Exp As Exception

        End Try
/*
more code for file processing here
*/

2 things:
1. I think Default.aspx.vb is missing following line:

InputText MyFile = new InputText;

as the code references NULL object. Am I right?
If I am right is it possible that this is the cause of the "Failure
writing the body"
error?

2. If I run the code on Mac where the file name will be something like
"/home/igor/temp/12345.bmp" will this code handle the name properly
and variable "c" will contain "12345.bmp"?

Thank you for any clarification.
>
> -lijo
>
>
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-07-15