Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Posting files with IdHttp

Posted on 2004-04-24
6
15,230 Views
Last Modified: 2012-05-04
Greetings..

I'm having problems with posting files witch over 3.5mb to IIS servers with the Indy IdHttp component.
I get this error: "Socket Error # 10054 Connection reset by peer"
In this code (witch is a part of idhttp)
---------
if (ARequest.Method in [hmPost, hmPut]) then
begin
  WriteStream(ARequest.Source, True, false);  <------this line
end;
---------
I've tried to post to apche server and that works... I find this very strange because there is no request made on my iis server when my app failes.

Here is the code I use to call the IdHttp.post function:
----------
formData := TIdMultiPartFormDataStream.Create;
formData.AddFile('File',fileName,'application/octet-stream');
HttpObject.Port := Port;
response := HttpObject.Post(posturl,formData);
-----------

I'm using "indy internet direct 9.0", Delphi 7 Enterprise on Windows XP.

Hope someone can help me.

Best regards,
Thorgeir
0
Comment
Question by:poxy
6 Comments
 
LVL 2

Expert Comment

by:PatrickMMartin
ID: 10909916
Well, using ASP.NET (my recommendation ) it seems to work fine with Indy:
you do need to check the parameters and the form field name.
The ASP.NET file saves the request so you should be able to see where the problem is.

Check this out : you need to put the test.aspx file in an IIS virtual directory and enter the URL

MainF.pas -----

unit MainF;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, StdCtrls, OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    IdHTTP1: TIdHTTP;
    btnPost: TButton;
    ebURL: TEdit;
    WebBrowser1: TWebBrowser;
    memResponse: TMemo;
    procedure btnPostClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
 IdMultiPartFormData
 ;

procedure TForm1.btnPostClick(Sender: TObject);
var
  formData : TIdMultiPartFormDataStream;
begin

  formData := TIdMultiPartFormDataStream.Create;
  formData.AddFile('File1', 'MainF.dfm', 'text/plain');
  idHTTP1.Port := 80;
  IdHTTP1.Request.Referer := ebURL.Text;
  memResponse.Lines.Text := idHTTP1.Post(ebURL.Text, formData);
  memResponse.Lines.SaveToFile('c:\temp\response.html');
  WebBrowser1.Navigate('c:\temp\response.html');

end;

end.


MainF.dfm --------

object Form1: TForm1
  Left = 192
  Top = 108
  Width = 696
  Height = 480
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object btnPost: TButton
    Left = 8
    Top = 16
    Width = 75
    Height = 25
    Caption = 'btnPost'
    TabOrder = 0
    OnClick = btnPostClick
  end
  object ebURL: TEdit
    Left = 112
    Top = 16
    Width = 377
    Height = 21
    TabOrder = 1
    Text = 'http://localhost/IDHTTPPost/test.aspx'
  end
  object WebBrowser1: TWebBrowser
    Left = 8
    Top = 232
    Width = 641
    Height = 201
    TabOrder = 2
    ControlData = {
      4C00000040420000C61400000000000000000000000000000000000000000000
      000000004C000000000000000000000001000000E0D057007335CF11AE690800
      2B2E126208000000000000004C0000000114020000000000C000000000000046
      8000000000000000000000000000000000000000000000000000000000000000
      00000000000000000100000000000000000000000000000000000000}
  end
  object memResponse: TMemo
    Left = 8
    Top = 48
    Width = 633
    Height = 177
    TabOrder = 3
  end
  object IdHTTP1: TIdHTTP
    MaxLineAction = maException
    ReadTimeout = 0
    AllowCookies = True
    ProxyParams.BasicAuthentication = False
    ProxyParams.ProxyPort = 0
    Request.ContentLength = -1
    Request.ContentRangeEnd = 0
    Request.ContentRangeStart = 0
    Request.ContentType = 'text/html'
    Request.Accept = 'text/html, */*'
    Request.BasicAuthentication = False
    Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
    HTTPOptions = [hoForceEncodeParams]
    Left = 112
    Top = 65520
  end
end

test.aspx -------


<%@ Page Language="C#" autoeventwireup="True" %>
<script runat="server">

    void Page_Load()
    {
      Request.SaveAs(@"c:\temp\request.txt", true);
   
       if (File1.PostedFile != null)
       {
          try
          {
             File1.PostedFile.SaveAs(@"c:\temp\" + Text1.Value);
             Span1.InnerHtml = "File uploaded successfully to <b>c:\\temp\\" +
                               Text1.Value + "</b> on the Web server";
          }
          catch (Exception exc)
          {
             Span1.InnerHtml = "Error saving file <b>c:\\temp\\" +
                               Text1.Value + "</b><br>" + exc.ToString();
          }
       }
   
    }
   
   
    void Button1_Click(object Source, EventArgs e)
    {
   
       if (Text1.Value == "")
       {
          Span1.InnerHtml = "Error: you must enter a file name";
          return;
       }
   
    }

</script>
<html>
<head>
</head>
<body>
    <h3>HtmlInputFile Sample
    </h3>
    <form enctype="multipart/form-data" runat="server">
        Select File to Upload:
        <input id="File1" type="file" runat="server" />
        <p>
            Save as filename (no path):
            <input id="Text1" type="text" value="loaded.tmp" runat="server" />
        </p>
        <p>
            <input id="Button1" type="button" value="Upload" runat="server" onserverclick="Button1_Click" />
            <span id="Span1" style="FONT: 8pt verdana" runat="server">
            <p>
            </p>
            </span>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
    </form>
</body>
</html>
0
 
LVL 1

Expert Comment

by:tanghz
ID: 10914485
How long will it take to finish uploading the full file ? I think this should be a problem with your configuation of Web Sever. Change the connection time out longer and have a try.

What is the service program on the server side to accept the uploading file?


IdHTTP1.Request.ContentType
Double chech this property from both sides. It will cause problems when not properly set up,.


0
 
LVL 4

Expert Comment

by:ceoworks
ID: 10931954
Hi, i think that it should be a problem with IIS or ASP. I don't know much about IIS but there may be a setting which defines the maximum upload file size. I developed that kind or program before which sends the files from Delphi client to the PHP script. I was using Apache as a server. I faced with the same problem(about 2MB). After changed the php.ini setting, everything worked fine.

Regards,
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:ceoworks
ID: 10931977
or it may be related with the timeout period..
0
 
LVL 2

Accepted Solution

by:
PatrickMMartin earned 400 total points
ID: 10932875
If the web server returned a serious error (500) Indy will throw an exception (which you should see). If there was literally no response, you could find out by stepping through the Indy code that reads the response (it's a bit awful).

If there are suspicions that the file size is a problem, test with varying sizes (ASP.NET defaults to a max request of around 4Mb, I believe ). However excessice file sizes will result in an immediate HTTP response, as it will read the content-length header.
This would not lead to a connection timeout.

Is the target you are posting to working?
Can you create a simple web page with a form and an input type="file" to attempt to post to it by hand?
0
 

Author Comment

by:poxy
ID: 10939134
Well the problem was the 4mb max file size in asp.net so thanks PatrickMMartin.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 316
Simple Delphi Question 9 96
Press three keys together and trigger a function 3 60
enhance the following code 3 37
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question