Page 1 of 2

how to upload image to server and paste url as the picture to rve?

Posted: Sat Jun 17, 2017 5:07 pm
by elGringo
Hello, Sergey, could you give a simple idea?

I want to

1. upload image to server and get url of this link ( know how to do) :D
2. paste this url as the picture to rve (don't know how to do)

one idea that i can see upload pic

insert file from the local storage
upload to server
handle OnSaveItemToFile like this

Code: Select all

procedure TMyForm.MyRichViewSaveItemToFile(

  Sender: TCustomRichView; const Path: String;

  RVData: TCustomRVData; ItemNo: Integer;

  SaveFormat: TRVSaveFormat; Unicode: Boolean;

  var OutStr: TRVRawByteString; var DoDefault: Boolean);

begin

  if (RVData.GetItemStyle(ItemNo)=rvsPicture) then

  begin

    if SaveFormat=rvsfHTML then

      OutStr := '<PIC>'

    else

      OutStr := '<PIC>'; // << insert URL here - but how can I know which url for which pic?

    if Unicode then

      OutStr := RVU_GetRawUnicode(OutStr);

    DoDefault := False;        

  end;

end;






Which way would be better? Could you give a simple example?
Thank you in advance for support.

P.S. using delphi seattle and TRichView 16+

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sat Jun 17, 2017 8:33 pm
by Sergey Tkachenko
Sorry, I do not understand the question.

Do you want to insert picture located on a web server to TRichViewEdit? In this case, see http://www.trichview.com/forums/viewtop ... f=3&t=5247

Or do you want to generate HTML containing references to images on a web server?

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sun Jun 18, 2017 9:19 am
by elGringo
Thank you for link - that i was needed!

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sat Jul 01, 2017 11:16 am
by elGringo
Hello again, tested your code. It downloads to rve well and converts well to .html file
But when i am trying to load it to RVE, using TRVHTMLImporter like this

Code: Select all

RVHTMLViewImporter.LoadFromFile(randomFilePath,rvequestion);
getting the problem (see pic on link)
https://yadi.sk/i/BQ8TpVy83Kep6

how to be?

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sat Jul 01, 2017 11:19 am
by elGringo
Hello again, tested your code. It downloads to rve well and converts well to .html file
But when i am trying to load it, using TRVHTMLImporter like this

Code: Select all

RVHTMLViewImporter.LoadFromFile(randomFilePath,rvequestion);
getting the problem
https://yadi.sk/i/BQ8TpVy83Kep6C

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sat Jul 01, 2017 7:16 pm
by Sergey Tkachenko
You need to process TRichView.OnImportPicture to download image from the remote server.

Do you use RichViewActions?

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sun Jul 02, 2017 4:34 am
by elGringo
Yes, I use them, could you give a small example, please?

Re: how to upload image to server and paste url as the picture to rve?

Posted: Tue Jul 04, 2017 5:45 pm
by Sergey Tkachenko
Place the following components on a form:
RVAIndyDownloadInterface: TRVAIndyDownloadInterface
IdHttp1: TIdHttp
Assign
RVAIndyDownloadInterface1.IdHttp = IdHttp1;
RVAControlPanel1.DownloadInterface = RVAIndyDownloadInterface1.

It's enough to download images from HTML and RTF files, when these files are loaded or pasted by RichViewActions.
However, you call RVHTMLViewImporter.LoadFromFile directly.
In this case, write:

Code: Select all

  RVAControlPanel1.InitImportPictures(nil, nil);
  RichViewEdit1.OnImportPicture := RVAControlPanel1.DoImportPicture;
  RVHTMLViewImporter.LoadFromFile(...)
  RVAControlPanel1.DoneImportPictures;
  RichViewEdit1.OnImportPicture := nil;
This code works if the assignments listed above are made.

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sun Jul 09, 2017 9:04 am
by elGringo
Your code works perfect, but 1 problem,

when i 1-st time add pic to rve i use something like this

Code: Select all

      if ARVE.InsertPicture('', gr, rvvaBaseline) then
        // RichViewEdit1.SetCurrentItemExtraIntProperty(rvepSpacing, 0, True);
        ARVE.SetCurrentItemExtraStrProperty(rvespImageFileName, ALink, True);
So i add url link as exraProperty

But when I use approach like you posted above link is lost, so if I will save again and load again it shows error - it cannot find the pic, because no link was saved.

So, question is how in your method add link as extraProperty?

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sun Jul 09, 2017 1:31 pm
by Sergey Tkachenko
Did you include rvsoUseItemImageFileNames in the Options parameter of SaveHTML/SaveHTMLEx?
If not, rvespImageFileName is not used when saving to HTML.

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sun Jul 09, 2017 2:54 pm
by elGringo
Good evening, Sergey!

yes, i use it, my code below

Code: Select all

procedure TTestsRvePanel.UpdateHTMLContenInDB;
var htmlContent:string;
    ss:TStringStream;

begin

 if rve.Visible then begin

     ss:=TStringStream.Create;
     try
      ss.Position:=0;
      rve.DeleteUnusedStyles(True, True, True);
      rve.ClearUndo;
      rve.SaveHTMLToStreamEx(ss,'','','','','','', [rvsoUTF8,rvsoUseCheckpointsNames, rvsoUseItemImageFileNames]);
      htmlContent:=ss.DataString;
     finally
     ss.Free;
     end;


 end else if Memo.Visible then htmlContent:=memo.Lines.Text;

 //update HTML content in descendants
 if Assigned(FOnUpdateHTMLContent) then FOnUpdateHTMLContent(htmlContent);

end;

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sun Jul 09, 2017 2:58 pm
by elGringo
As I understand, somewhere here url is not assigned again

Code: Select all

 RichViewEdit1.OnImportPicture := RVAControlPanel1.DoImportPicture;

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sun Jul 09, 2017 3:31 pm
by Sergey Tkachenko
Include rvoAssignImageFileNames in RichViewEdit1.Options.

Re: how to upload image to server and paste url as the picture to rve?

Posted: Sun Jul 09, 2017 3:39 pm
by elGringo
Perfect! It works, just works !!! Thank you very much, Sergey!!!

Re: how to upload image to server and paste url as the picture to rve?

Posted: Mon Jul 10, 2017 11:03 am
by elGringo
One more little question - how to adjust size of pics? When i insert picture it inserts it with origin sizes, when i convert to html i see code like this

Code: Select all

<p><img width=16 height=16 alt="" style="padding : 1px;" src="http://localhost:40000/public/files/61/2017/7/8/addlist.png"></p>
How can I adjust width and height of pic, when i do like this

Code: Select all

procedure InsertPic(ARVE:TRichViewEdit; ALink:string);
var Gr: TGraphic;
begin
//
  ARVE.Enabled := False;

    try
     Gr := DownloadImage(ALink);
      if Gr=nil then
         exit;
      ARVE.TopLevelEditor.BeginUndoGroup(rvutInsert);
      ARVE.TopLevelEditor.SetUndoGroupMode(True);


     try

        if ARVE.InsertPicture('', gr, rvvaBaseline) then
          // RichViewEdit1.SetCurrentItemExtraIntProperty(rvepSpacing, 0, True);
          ARVE.SetCurrentItemExtraStrProperty(rvespImageFileName, ALink, True);
  //        ARVE.SetCurrentItemExtraStrProperty(rvespAlt, '', True);
  //        ARVE.SetCurrentItemExtraStrProperty(rvespHint, '', True);

     finally
       ARVE.TopLevelEditor.SetUndoGroupMode(False);
     end;

    finally
    ARVE.Enabled := True;
    end;

end;