Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7639131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:20:28+00:00 2026-05-31T08:20:28+00:00

I’m trying to resume an upload using indy (HTTP Post), the code looks like

  • 0

I’m trying to resume an upload using indy (HTTP Post), the code looks like this (using Delphi 2010, Indy 10.4736):

 IdHttp.Head('http://localhost/_tests/resume/large-file.bin');
 ByteRange           := IdHttp.Response.ContentLength + 1;

 // Attach the file to post/upload
 Stream              := TIdMultipartFormDataStream.Create;
 with Stream.AddFile('upload_file', 'D:\large-file.bin', 'application/octet-stream') do
 begin
      HeaderCharset  := 'utf-8';
      HeaderEncoding := '8';
 end;    // with

 with IdHTTP do
 begin
      IOHandler.LargeStream           := True;

      with Request do
      begin
           ContentRangeStart          := ByteRange;
           ContentRangeEnd            := (Stream.Size - ByteRange);
           ContentLength              := ContentRangeEnd;
           ContentRangeInstanceLength := ContentLength;
      end;    // with

      Post('http://localhost/_tests/resume/t1.php', Stream);
 end;    // with

but upload resume doesn’t work 🙁

I looked into Indy’s code, it seems that this function in IdIOHandler.pas

TIdIOHandler.Write()

always deal with complete streams/files (since the parameter ASize: TIdStreamSize seems to be always 0, which according to the code means sending the full file/stream).

This prevents indy from resuming the upload.

My question is: is it possible to avoid sending the full file?

Setting content range didn’t change anything. I also tweaked indy’s code (modified 3 lines) to make indy obey to the content range / stream position, but it’s buggy and indy always end up hanging in IdStackWindows.pas because of an infinite timeout here:

TIdSocketListWindows.FDSelect()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:20:29+00:00Added an answer on May 31, 2026 at 8:20 am

    As I told you in your earlier question, you have to post a TStream containing the remaining file data to upload. Don’t use TIdMultipartFormDataStream.AddFile(), as that will send the entire file. Use the TStream overloaded version of TIdMultipartFormDataStream.AddFormField() instead.

    And TIdHTTP is not designed to respect the ContentRange... properties. Most of the Request properties merely set the corresponding HTTP headers only, they do not influence the data. That is why your edits broke it.

    Try this:

    IdHttp.Head('http://localhost/_tests/resume/large-file.bin');
    FileSize := IdHttp.Response.ContentLength;
    
    FileStrm := TFileStream.Create('D:\large-file.bin', fmOpenRead or fmShareDenyWrite);
    try
      if FileSize < FileStrm.Size then
      begin
        FileStrm.Position := FileSize;
    
        Stream := TIdMultipartFormDataStream.Create;
        try
          with Stream.AddFormField('upload_file', 'application/octet-stream', '', FileStrm, 'large-file.bin') do
          begin
            HeaderCharset  := 'utf-8';
            HeaderEncoding := '8';
          end;
    
          with IdHTTP do
          begin
            with Request do
            begin
              ContentRangeStart := FileSize + 1;
              ContentRangeEnd   := FileStrm.Size;
            end;
    
            Post('http://localhost/_tests/resume/t1.php', Stream);
          end;
        finally
          Stream.Free;
        end;
      end;
    finally
      FileStrm.Free;
    end;
    

    With that said, this is a GROSS MISUSE of HTTP and multipart/form-data. For starters, the ContentRange values are in the wrong place. You are applying them to the entire Request as a whole, which is wrong. They would need to be applied at the FormField instead, but TIdMultipartFormDataStream does not currently support that. Second, multipart/form-data was not designed to be used like this anyway. It is fine for uploading a file from the beginning, but not for resuming a broken upload. You really should stop using TIdMultipartFormDataStream and just pass the file data directly to TIdHTTP.Post() like I suggested earlier, eg:

    FileStrm := TFileStream.Create('D:\large-file.bin', fmOpenRead or fmShareDenyWrite);
    try
      IdHTTP.Post('http://localhost/_tests/upload.php?name=large-file.bin', FileStrm);
    finally
      FileStrm.Free;
    end;
    

    .

    IdHTTP.Head('http://localhost/_tests/files/large-file.bin');
    FileSize := IdHTTP.Response.ContentLength;
    
    FileStrm := TFileStream.Create('D:\large-file.bin', fmOpenRead or fmShareDenyWrite);
    try
      if FileSize < FileStrm.Size then
      begin
        FileStrm.Position := FileSize;
        IdHTTP.Post('http://localhost/_tests/resume.php?name=large-file.bin', FileStrm);
      end;
    finally
      FileStrm.Free;
    end;
    

    I already explained earlier how to access the raw POST data in PHP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.