Trouble sending JPG via Tidtrivialftp. File received is 0KBJPEG Error #42 on assignUdp image streaming, delphi indy10Using a COM DLL in delphi - Access violation in MSVCR80D.dll errorHow to find encoding of a file in Unix via script(s)How to remove files and directories quickly via terminal (bash shell)How to Create a Simple Dictation Pad in Delphi2009+VistaSend and Receive a simple string value with Indy (Delphi)Sending and receiving data streams in DelphiPost values in HTMLforms without using TwebBrowserSelect Cell in TAdvStringGrid with hidden columnsDelphi XE3 Invalid Pointer when trying to free FSQL (TStringList)Connect to Dropbox API using intents in Delphi Firemonkey

How can God warn people of the upcoming rapture without disrupting society?

Did DOS zero out the BSS area when it loaded a program?

Crippling fear of hellfire &, damnation, please help?

How would you translate this? バタコチーズライス

Global BGP Routing only by only importing supernet prefixes

Installing Windows to flash UEFI/ BIOS, then reinstalling Ubuntu

Why aren't rainbows blurred-out into nothing after they are produced?

Transition to "Starvation Mode" in Survival Situations

Is it possible to arrive in the US without a C-1 visa for a transit flight

Pokemon Go: Gym Badge Over-completed?

What are those bumps on top of the Antonov-225?

Stephen King and steam/diesel/cyber-punk

Dogfights in outer space

Locked Room Murder!! How and who?

Why aren’t there water shutoff valves for each room?

Scam? Phone call from "Department of Social Security" asking me to call back

Will using a resistor in series with a LED to control its voltage increase the total energy expenditure?

Why does cat'ing a file via ssh result in control characters?

How can I communicate my issues with a potential date's pushy behavior?

A torrent of foreign terms

How do I call a 6-digit Australian phone number with a US-based mobile phone?

How should I write this passage to make it the most readable?

Is this n-speak?

When did Bilbo and Frodo learn that Gandalf was a Maia?



Trouble sending JPG via Tidtrivialftp. File received is 0KB


JPEG Error #42 on assignUdp image streaming, delphi indy10Using a COM DLL in delphi - Access violation in MSVCR80D.dll errorHow to find encoding of a file in Unix via script(s)How to remove files and directories quickly via terminal (bash shell)How to Create a Simple Dictation Pad in Delphi2009+VistaSend and Receive a simple string value with Indy (Delphi)Sending and receiving data streams in DelphiPost values in HTMLforms without using TwebBrowserSelect Cell in TAdvStringGrid with hidden columnsDelphi XE3 Invalid Pointer when trying to free FSQL (TStringList)Connect to Dropbox API using intents in Delphi Firemonkey






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am setting up a software (SOFT1) that takes video frame grabs in JPG format and sent to another software (SOFT2) using Tidtrivialftp.



SOFT2 is to receive the Jpeg and display in a TImage for review.



I am not sure what I am doing wrong. The code is a cut and paste from another post on here. It seems to work but I get nothing in my TImage and if I try to save to disk I get a 0KB file.



I tried implementing the solution found on this link:



Udp image streaming, delphi indy10



Trying to send a small test.jpg which is only 2.48KB for testing purpose.



Client Side:



procedure TForm1.BtnClick(Sender: TObject);
var
Myjpg: TJPEGImage;
Strmkoko : TMemoryStream;
begin

try
//Tried a lot of different ways to load the jpg into a stream. This is the latest one with same results.

Strmkoko := TMemoryStream.Create;
Myjpg := TJPEGImage.Create;
Myjpg.LoadFromFile('C:UsersEtienneDesktopMyVideoatest.jpg');
Myjpg.SaveToStream(Strmkoko);
Strmkoko.Position := 0;
Image1.Picture.assign(Myjpg); //Confirming MyJpg is showing the picture by placing it in a TImage component before sending - All ok

//Also tried to just put the filename instead of stream. - no difference
IdtrivialFTPClientFrameGrab.Put(Strmkoko, 'test.jpg');

finally
Strmkoko.Free;
Myjpg.Free;
end;
end;


Server Side:



procedure TForm2.IdFTPServerFrameGrabTransferComplete(Sender: TObject;
const Success: Boolean; const PeerInfo: TPeerInfo; var AStream: TStream;
const WriteOperation: Boolean);
var
jpg: TJPEGImage;
begin
if WriteOperation and Success then
begin
jpg := TJPEGImage.Create;
try
jpg.LoadFromStream(AStream);
jpg.SaveToFile('C:UsersEtienneDesktopPictest.jpg'); //trying to save the jpg to check what I get and its 0KB
img1.Picture.Assign(jpg); //This is the final place I want to send the stream
finally
jpg.Free;
end;
end;
end;

procedure TForm2.IdFTPServerFrameGrabWriteFile(Sender: TObject;
var FileName: string; const PeerInfo: TPeerInfo; var GrantAccess: Boolean;
var AStream: TStream; var FreeStreamOnComplete: Boolean);
begin
if Filename = 'test.jpg' then
begin
//Code does get in here when I debug
GrantAccess := True;
AStream := TMemoryStream.Create;
FreeStreamOnComplete := True;
end else
GrantAccess := False;
end;


I am expecting the file I am sending (test.jpg) to appear in img1 and also be saved in 'C:UsersEtienneDesktopPictest.jpg'



The code does work in the way that it saved the file and assign it to img1 but its empty.



This is all done locally.



Its like "IdtrivialFTPClientFrameGrab.Put(Strmkoko, 'test.jpg');" is sending an empty file. But I have tried several ways to load the stream and always the same result.



I understand that TCP/IP would be better but I would like to get this to work. Any help would be appreciated.



Cheers,
E.










share|improve this question


























  • Host and port for IdtrivialFTPClientFrameGrab are previously assigned.

    – E Demers
    Mar 27 at 11:08






  • 1





    On a side note, you should avoid using TJPEGImage.SaveToStream() in this situation, as that will re-encode the image and lose image quality (JPG is a lossy format, quality is lost every time it is re-encoded). When sending a file, you should load it directly into your TMemoryStream first, and then load that stream into TJPEGImage if needed. When receiving a file, save the TMemoryStream directly to file, and load the stream into TJPEGImage if needed. This way, the receiver ends up with an exact duplicate of the original file, not a lossy version of it.

    – Remy Lebeau
    Mar 27 at 19:30











  • Thank you for the comments. I posted here the last attempt but once I got it working I ended up just passing the file name to the put command as follow: "IdtrivialFTPClientFrameGrab.Put(Filename, 'test.jpg');"

    – E Demers
    Mar 28 at 6:47


















1















I am setting up a software (SOFT1) that takes video frame grabs in JPG format and sent to another software (SOFT2) using Tidtrivialftp.



SOFT2 is to receive the Jpeg and display in a TImage for review.



I am not sure what I am doing wrong. The code is a cut and paste from another post on here. It seems to work but I get nothing in my TImage and if I try to save to disk I get a 0KB file.



I tried implementing the solution found on this link:



Udp image streaming, delphi indy10



Trying to send a small test.jpg which is only 2.48KB for testing purpose.



Client Side:



procedure TForm1.BtnClick(Sender: TObject);
var
Myjpg: TJPEGImage;
Strmkoko : TMemoryStream;
begin

try
//Tried a lot of different ways to load the jpg into a stream. This is the latest one with same results.

Strmkoko := TMemoryStream.Create;
Myjpg := TJPEGImage.Create;
Myjpg.LoadFromFile('C:UsersEtienneDesktopMyVideoatest.jpg');
Myjpg.SaveToStream(Strmkoko);
Strmkoko.Position := 0;
Image1.Picture.assign(Myjpg); //Confirming MyJpg is showing the picture by placing it in a TImage component before sending - All ok

//Also tried to just put the filename instead of stream. - no difference
IdtrivialFTPClientFrameGrab.Put(Strmkoko, 'test.jpg');

finally
Strmkoko.Free;
Myjpg.Free;
end;
end;


Server Side:



procedure TForm2.IdFTPServerFrameGrabTransferComplete(Sender: TObject;
const Success: Boolean; const PeerInfo: TPeerInfo; var AStream: TStream;
const WriteOperation: Boolean);
var
jpg: TJPEGImage;
begin
if WriteOperation and Success then
begin
jpg := TJPEGImage.Create;
try
jpg.LoadFromStream(AStream);
jpg.SaveToFile('C:UsersEtienneDesktopPictest.jpg'); //trying to save the jpg to check what I get and its 0KB
img1.Picture.Assign(jpg); //This is the final place I want to send the stream
finally
jpg.Free;
end;
end;
end;

procedure TForm2.IdFTPServerFrameGrabWriteFile(Sender: TObject;
var FileName: string; const PeerInfo: TPeerInfo; var GrantAccess: Boolean;
var AStream: TStream; var FreeStreamOnComplete: Boolean);
begin
if Filename = 'test.jpg' then
begin
//Code does get in here when I debug
GrantAccess := True;
AStream := TMemoryStream.Create;
FreeStreamOnComplete := True;
end else
GrantAccess := False;
end;


I am expecting the file I am sending (test.jpg) to appear in img1 and also be saved in 'C:UsersEtienneDesktopPictest.jpg'



The code does work in the way that it saved the file and assign it to img1 but its empty.



This is all done locally.



Its like "IdtrivialFTPClientFrameGrab.Put(Strmkoko, 'test.jpg');" is sending an empty file. But I have tried several ways to load the stream and always the same result.



I understand that TCP/IP would be better but I would like to get this to work. Any help would be appreciated.



Cheers,
E.










share|improve this question


























  • Host and port for IdtrivialFTPClientFrameGrab are previously assigned.

    – E Demers
    Mar 27 at 11:08






  • 1





    On a side note, you should avoid using TJPEGImage.SaveToStream() in this situation, as that will re-encode the image and lose image quality (JPG is a lossy format, quality is lost every time it is re-encoded). When sending a file, you should load it directly into your TMemoryStream first, and then load that stream into TJPEGImage if needed. When receiving a file, save the TMemoryStream directly to file, and load the stream into TJPEGImage if needed. This way, the receiver ends up with an exact duplicate of the original file, not a lossy version of it.

    – Remy Lebeau
    Mar 27 at 19:30











  • Thank you for the comments. I posted here the last attempt but once I got it working I ended up just passing the file name to the put command as follow: "IdtrivialFTPClientFrameGrab.Put(Filename, 'test.jpg');"

    – E Demers
    Mar 28 at 6:47














1












1








1








I am setting up a software (SOFT1) that takes video frame grabs in JPG format and sent to another software (SOFT2) using Tidtrivialftp.



SOFT2 is to receive the Jpeg and display in a TImage for review.



I am not sure what I am doing wrong. The code is a cut and paste from another post on here. It seems to work but I get nothing in my TImage and if I try to save to disk I get a 0KB file.



I tried implementing the solution found on this link:



Udp image streaming, delphi indy10



Trying to send a small test.jpg which is only 2.48KB for testing purpose.



Client Side:



procedure TForm1.BtnClick(Sender: TObject);
var
Myjpg: TJPEGImage;
Strmkoko : TMemoryStream;
begin

try
//Tried a lot of different ways to load the jpg into a stream. This is the latest one with same results.

Strmkoko := TMemoryStream.Create;
Myjpg := TJPEGImage.Create;
Myjpg.LoadFromFile('C:UsersEtienneDesktopMyVideoatest.jpg');
Myjpg.SaveToStream(Strmkoko);
Strmkoko.Position := 0;
Image1.Picture.assign(Myjpg); //Confirming MyJpg is showing the picture by placing it in a TImage component before sending - All ok

//Also tried to just put the filename instead of stream. - no difference
IdtrivialFTPClientFrameGrab.Put(Strmkoko, 'test.jpg');

finally
Strmkoko.Free;
Myjpg.Free;
end;
end;


Server Side:



procedure TForm2.IdFTPServerFrameGrabTransferComplete(Sender: TObject;
const Success: Boolean; const PeerInfo: TPeerInfo; var AStream: TStream;
const WriteOperation: Boolean);
var
jpg: TJPEGImage;
begin
if WriteOperation and Success then
begin
jpg := TJPEGImage.Create;
try
jpg.LoadFromStream(AStream);
jpg.SaveToFile('C:UsersEtienneDesktopPictest.jpg'); //trying to save the jpg to check what I get and its 0KB
img1.Picture.Assign(jpg); //This is the final place I want to send the stream
finally
jpg.Free;
end;
end;
end;

procedure TForm2.IdFTPServerFrameGrabWriteFile(Sender: TObject;
var FileName: string; const PeerInfo: TPeerInfo; var GrantAccess: Boolean;
var AStream: TStream; var FreeStreamOnComplete: Boolean);
begin
if Filename = 'test.jpg' then
begin
//Code does get in here when I debug
GrantAccess := True;
AStream := TMemoryStream.Create;
FreeStreamOnComplete := True;
end else
GrantAccess := False;
end;


I am expecting the file I am sending (test.jpg) to appear in img1 and also be saved in 'C:UsersEtienneDesktopPictest.jpg'



The code does work in the way that it saved the file and assign it to img1 but its empty.



This is all done locally.



Its like "IdtrivialFTPClientFrameGrab.Put(Strmkoko, 'test.jpg');" is sending an empty file. But I have tried several ways to load the stream and always the same result.



I understand that TCP/IP would be better but I would like to get this to work. Any help would be appreciated.



Cheers,
E.










share|improve this question
















I am setting up a software (SOFT1) that takes video frame grabs in JPG format and sent to another software (SOFT2) using Tidtrivialftp.



SOFT2 is to receive the Jpeg and display in a TImage for review.



I am not sure what I am doing wrong. The code is a cut and paste from another post on here. It seems to work but I get nothing in my TImage and if I try to save to disk I get a 0KB file.



I tried implementing the solution found on this link:



Udp image streaming, delphi indy10



Trying to send a small test.jpg which is only 2.48KB for testing purpose.



Client Side:



procedure TForm1.BtnClick(Sender: TObject);
var
Myjpg: TJPEGImage;
Strmkoko : TMemoryStream;
begin

try
//Tried a lot of different ways to load the jpg into a stream. This is the latest one with same results.

Strmkoko := TMemoryStream.Create;
Myjpg := TJPEGImage.Create;
Myjpg.LoadFromFile('C:UsersEtienneDesktopMyVideoatest.jpg');
Myjpg.SaveToStream(Strmkoko);
Strmkoko.Position := 0;
Image1.Picture.assign(Myjpg); //Confirming MyJpg is showing the picture by placing it in a TImage component before sending - All ok

//Also tried to just put the filename instead of stream. - no difference
IdtrivialFTPClientFrameGrab.Put(Strmkoko, 'test.jpg');

finally
Strmkoko.Free;
Myjpg.Free;
end;
end;


Server Side:



procedure TForm2.IdFTPServerFrameGrabTransferComplete(Sender: TObject;
const Success: Boolean; const PeerInfo: TPeerInfo; var AStream: TStream;
const WriteOperation: Boolean);
var
jpg: TJPEGImage;
begin
if WriteOperation and Success then
begin
jpg := TJPEGImage.Create;
try
jpg.LoadFromStream(AStream);
jpg.SaveToFile('C:UsersEtienneDesktopPictest.jpg'); //trying to save the jpg to check what I get and its 0KB
img1.Picture.Assign(jpg); //This is the final place I want to send the stream
finally
jpg.Free;
end;
end;
end;

procedure TForm2.IdFTPServerFrameGrabWriteFile(Sender: TObject;
var FileName: string; const PeerInfo: TPeerInfo; var GrantAccess: Boolean;
var AStream: TStream; var FreeStreamOnComplete: Boolean);
begin
if Filename = 'test.jpg' then
begin
//Code does get in here when I debug
GrantAccess := True;
AStream := TMemoryStream.Create;
FreeStreamOnComplete := True;
end else
GrantAccess := False;
end;


I am expecting the file I am sending (test.jpg) to appear in img1 and also be saved in 'C:UsersEtienneDesktopPictest.jpg'



The code does work in the way that it saved the file and assign it to img1 but its empty.



This is all done locally.



Its like "IdtrivialFTPClientFrameGrab.Put(Strmkoko, 'test.jpg');" is sending an empty file. But I have tried several ways to load the stream and always the same result.



I understand that TCP/IP would be better but I would like to get this to work. Any help would be appreciated.



Cheers,
E.







file delphi udp indy transfer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 18:35









mjn

26.5k24 gold badges145 silver badges323 bronze badges




26.5k24 gold badges145 silver badges323 bronze badges










asked Mar 27 at 10:52









E DemersE Demers

165 bronze badges




165 bronze badges















  • Host and port for IdtrivialFTPClientFrameGrab are previously assigned.

    – E Demers
    Mar 27 at 11:08






  • 1





    On a side note, you should avoid using TJPEGImage.SaveToStream() in this situation, as that will re-encode the image and lose image quality (JPG is a lossy format, quality is lost every time it is re-encoded). When sending a file, you should load it directly into your TMemoryStream first, and then load that stream into TJPEGImage if needed. When receiving a file, save the TMemoryStream directly to file, and load the stream into TJPEGImage if needed. This way, the receiver ends up with an exact duplicate of the original file, not a lossy version of it.

    – Remy Lebeau
    Mar 27 at 19:30











  • Thank you for the comments. I posted here the last attempt but once I got it working I ended up just passing the file name to the put command as follow: "IdtrivialFTPClientFrameGrab.Put(Filename, 'test.jpg');"

    – E Demers
    Mar 28 at 6:47


















  • Host and port for IdtrivialFTPClientFrameGrab are previously assigned.

    – E Demers
    Mar 27 at 11:08






  • 1





    On a side note, you should avoid using TJPEGImage.SaveToStream() in this situation, as that will re-encode the image and lose image quality (JPG is a lossy format, quality is lost every time it is re-encoded). When sending a file, you should load it directly into your TMemoryStream first, and then load that stream into TJPEGImage if needed. When receiving a file, save the TMemoryStream directly to file, and load the stream into TJPEGImage if needed. This way, the receiver ends up with an exact duplicate of the original file, not a lossy version of it.

    – Remy Lebeau
    Mar 27 at 19:30











  • Thank you for the comments. I posted here the last attempt but once I got it working I ended up just passing the file name to the put command as follow: "IdtrivialFTPClientFrameGrab.Put(Filename, 'test.jpg');"

    – E Demers
    Mar 28 at 6:47

















Host and port for IdtrivialFTPClientFrameGrab are previously assigned.

– E Demers
Mar 27 at 11:08





Host and port for IdtrivialFTPClientFrameGrab are previously assigned.

– E Demers
Mar 27 at 11:08




1




1





On a side note, you should avoid using TJPEGImage.SaveToStream() in this situation, as that will re-encode the image and lose image quality (JPG is a lossy format, quality is lost every time it is re-encoded). When sending a file, you should load it directly into your TMemoryStream first, and then load that stream into TJPEGImage if needed. When receiving a file, save the TMemoryStream directly to file, and load the stream into TJPEGImage if needed. This way, the receiver ends up with an exact duplicate of the original file, not a lossy version of it.

– Remy Lebeau
Mar 27 at 19:30





On a side note, you should avoid using TJPEGImage.SaveToStream() in this situation, as that will re-encode the image and lose image quality (JPG is a lossy format, quality is lost every time it is re-encoded). When sending a file, you should load it directly into your TMemoryStream first, and then load that stream into TJPEGImage if needed. When receiving a file, save the TMemoryStream directly to file, and load the stream into TJPEGImage if needed. This way, the receiver ends up with an exact duplicate of the original file, not a lossy version of it.

– Remy Lebeau
Mar 27 at 19:30













Thank you for the comments. I posted here the last attempt but once I got it working I ended up just passing the file name to the put command as follow: "IdtrivialFTPClientFrameGrab.Put(Filename, 'test.jpg');"

– E Demers
Mar 28 at 6:47






Thank you for the comments. I posted here the last attempt but once I got it working I ended up just passing the file name to the put command as follow: "IdtrivialFTPClientFrameGrab.Put(Filename, 'test.jpg');"

– E Demers
Mar 28 at 6:47













1 Answer
1






active

oldest

votes


















1














After a lot of trials I figured out the problem. I do not know why it was omitted from the examples shown in the other posts but after you received the Stream you have to reset its position before you can load it...



AStream.Position := 0;



procedure TForm2.IdFTPServerFrameGrabTransferComplete(Sender: TObject;
const Success: Boolean; const PeerInfo: TPeerInfo; var AStream: TStream;
const WriteOperation: Boolean);
var
jpg: TJPEGImage;
begin
if WriteOperation and Success then
begin
jpg := TJPEGImage.Create;
try
AStream.Position := 0; // <----- insert here
jpg.LoadFromStream(AStream);
jpg.SaveToFile('C:UsersEtienneDesktopPictest.jpg'); //trying to save the jpg to check what I get and its 0KB
img1.Picture.Assign(jpg); //This is the final place I want to send the stream
finally
jpg.Free;
end;
end;
end;





share|improve this answer




















  • 1





    I updated my earlier example to include the Position reset. The reason TIdTrivialFTPServer does not reset the Position automatically is because the user of the component can provide custom streams and so the server does not make any assumptions about what the user intends to do with a stream after its transfer is complete. By default, an inbound transfer is merely saved to a disk file, and that does not require resetting the Position. But if the user wants to load the stream data into a UI, for instance, then the user needs to reset the Position as needed.

    – Remy Lebeau
    Mar 27 at 19:24












  • Makes sense, thank you for the input. The try loop prevented me from getting the "JPEG ERROR #42" which pointed me to the right solution found here: stackoverflow.com/questions/19387569/jpeg-error-42-on-assign

    – E Demers
    Mar 28 at 6:44











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55375444%2ftrouble-sending-jpg-via-tidtrivialftp-file-received-is-0kb%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














After a lot of trials I figured out the problem. I do not know why it was omitted from the examples shown in the other posts but after you received the Stream you have to reset its position before you can load it...



AStream.Position := 0;



procedure TForm2.IdFTPServerFrameGrabTransferComplete(Sender: TObject;
const Success: Boolean; const PeerInfo: TPeerInfo; var AStream: TStream;
const WriteOperation: Boolean);
var
jpg: TJPEGImage;
begin
if WriteOperation and Success then
begin
jpg := TJPEGImage.Create;
try
AStream.Position := 0; // <----- insert here
jpg.LoadFromStream(AStream);
jpg.SaveToFile('C:UsersEtienneDesktopPictest.jpg'); //trying to save the jpg to check what I get and its 0KB
img1.Picture.Assign(jpg); //This is the final place I want to send the stream
finally
jpg.Free;
end;
end;
end;





share|improve this answer




















  • 1





    I updated my earlier example to include the Position reset. The reason TIdTrivialFTPServer does not reset the Position automatically is because the user of the component can provide custom streams and so the server does not make any assumptions about what the user intends to do with a stream after its transfer is complete. By default, an inbound transfer is merely saved to a disk file, and that does not require resetting the Position. But if the user wants to load the stream data into a UI, for instance, then the user needs to reset the Position as needed.

    – Remy Lebeau
    Mar 27 at 19:24












  • Makes sense, thank you for the input. The try loop prevented me from getting the "JPEG ERROR #42" which pointed me to the right solution found here: stackoverflow.com/questions/19387569/jpeg-error-42-on-assign

    – E Demers
    Mar 28 at 6:44
















1














After a lot of trials I figured out the problem. I do not know why it was omitted from the examples shown in the other posts but after you received the Stream you have to reset its position before you can load it...



AStream.Position := 0;



procedure TForm2.IdFTPServerFrameGrabTransferComplete(Sender: TObject;
const Success: Boolean; const PeerInfo: TPeerInfo; var AStream: TStream;
const WriteOperation: Boolean);
var
jpg: TJPEGImage;
begin
if WriteOperation and Success then
begin
jpg := TJPEGImage.Create;
try
AStream.Position := 0; // <----- insert here
jpg.LoadFromStream(AStream);
jpg.SaveToFile('C:UsersEtienneDesktopPictest.jpg'); //trying to save the jpg to check what I get and its 0KB
img1.Picture.Assign(jpg); //This is the final place I want to send the stream
finally
jpg.Free;
end;
end;
end;





share|improve this answer




















  • 1





    I updated my earlier example to include the Position reset. The reason TIdTrivialFTPServer does not reset the Position automatically is because the user of the component can provide custom streams and so the server does not make any assumptions about what the user intends to do with a stream after its transfer is complete. By default, an inbound transfer is merely saved to a disk file, and that does not require resetting the Position. But if the user wants to load the stream data into a UI, for instance, then the user needs to reset the Position as needed.

    – Remy Lebeau
    Mar 27 at 19:24












  • Makes sense, thank you for the input. The try loop prevented me from getting the "JPEG ERROR #42" which pointed me to the right solution found here: stackoverflow.com/questions/19387569/jpeg-error-42-on-assign

    – E Demers
    Mar 28 at 6:44














1












1








1







After a lot of trials I figured out the problem. I do not know why it was omitted from the examples shown in the other posts but after you received the Stream you have to reset its position before you can load it...



AStream.Position := 0;



procedure TForm2.IdFTPServerFrameGrabTransferComplete(Sender: TObject;
const Success: Boolean; const PeerInfo: TPeerInfo; var AStream: TStream;
const WriteOperation: Boolean);
var
jpg: TJPEGImage;
begin
if WriteOperation and Success then
begin
jpg := TJPEGImage.Create;
try
AStream.Position := 0; // <----- insert here
jpg.LoadFromStream(AStream);
jpg.SaveToFile('C:UsersEtienneDesktopPictest.jpg'); //trying to save the jpg to check what I get and its 0KB
img1.Picture.Assign(jpg); //This is the final place I want to send the stream
finally
jpg.Free;
end;
end;
end;





share|improve this answer













After a lot of trials I figured out the problem. I do not know why it was omitted from the examples shown in the other posts but after you received the Stream you have to reset its position before you can load it...



AStream.Position := 0;



procedure TForm2.IdFTPServerFrameGrabTransferComplete(Sender: TObject;
const Success: Boolean; const PeerInfo: TPeerInfo; var AStream: TStream;
const WriteOperation: Boolean);
var
jpg: TJPEGImage;
begin
if WriteOperation and Success then
begin
jpg := TJPEGImage.Create;
try
AStream.Position := 0; // <----- insert here
jpg.LoadFromStream(AStream);
jpg.SaveToFile('C:UsersEtienneDesktopPictest.jpg'); //trying to save the jpg to check what I get and its 0KB
img1.Picture.Assign(jpg); //This is the final place I want to send the stream
finally
jpg.Free;
end;
end;
end;






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 15:35









E DemersE Demers

165 bronze badges




165 bronze badges










  • 1





    I updated my earlier example to include the Position reset. The reason TIdTrivialFTPServer does not reset the Position automatically is because the user of the component can provide custom streams and so the server does not make any assumptions about what the user intends to do with a stream after its transfer is complete. By default, an inbound transfer is merely saved to a disk file, and that does not require resetting the Position. But if the user wants to load the stream data into a UI, for instance, then the user needs to reset the Position as needed.

    – Remy Lebeau
    Mar 27 at 19:24












  • Makes sense, thank you for the input. The try loop prevented me from getting the "JPEG ERROR #42" which pointed me to the right solution found here: stackoverflow.com/questions/19387569/jpeg-error-42-on-assign

    – E Demers
    Mar 28 at 6:44













  • 1





    I updated my earlier example to include the Position reset. The reason TIdTrivialFTPServer does not reset the Position automatically is because the user of the component can provide custom streams and so the server does not make any assumptions about what the user intends to do with a stream after its transfer is complete. By default, an inbound transfer is merely saved to a disk file, and that does not require resetting the Position. But if the user wants to load the stream data into a UI, for instance, then the user needs to reset the Position as needed.

    – Remy Lebeau
    Mar 27 at 19:24












  • Makes sense, thank you for the input. The try loop prevented me from getting the "JPEG ERROR #42" which pointed me to the right solution found here: stackoverflow.com/questions/19387569/jpeg-error-42-on-assign

    – E Demers
    Mar 28 at 6:44








1




1





I updated my earlier example to include the Position reset. The reason TIdTrivialFTPServer does not reset the Position automatically is because the user of the component can provide custom streams and so the server does not make any assumptions about what the user intends to do with a stream after its transfer is complete. By default, an inbound transfer is merely saved to a disk file, and that does not require resetting the Position. But if the user wants to load the stream data into a UI, for instance, then the user needs to reset the Position as needed.

– Remy Lebeau
Mar 27 at 19:24






I updated my earlier example to include the Position reset. The reason TIdTrivialFTPServer does not reset the Position automatically is because the user of the component can provide custom streams and so the server does not make any assumptions about what the user intends to do with a stream after its transfer is complete. By default, an inbound transfer is merely saved to a disk file, and that does not require resetting the Position. But if the user wants to load the stream data into a UI, for instance, then the user needs to reset the Position as needed.

– Remy Lebeau
Mar 27 at 19:24














Makes sense, thank you for the input. The try loop prevented me from getting the "JPEG ERROR #42" which pointed me to the right solution found here: stackoverflow.com/questions/19387569/jpeg-error-42-on-assign

– E Demers
Mar 28 at 6:44






Makes sense, thank you for the input. The try loop prevented me from getting the "JPEG ERROR #42" which pointed me to the right solution found here: stackoverflow.com/questions/19387569/jpeg-error-42-on-assign

– E Demers
Mar 28 at 6:44









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55375444%2ftrouble-sending-jpg-via-tidtrivialftp-file-received-is-0kb%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript