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

General TRichView support forum. Please post your questions here
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post 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+
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post 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?
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post by elGringo »

Thank you for link - that i was needed!
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post 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?
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post 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
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post by Sergey Tkachenko »

You need to process TRichView.OnImportPicture to download image from the remote server.

Do you use RichViewActions?
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post by elGringo »

Yes, I use them, could you give a small example, please?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post 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.
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post by Sergey Tkachenko »

Did you include rvsoUseItemImageFileNames in the Options parameter of SaveHTML/SaveHTMLEx?
If not, rvespImageFileName is not used when saving to HTML.
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post 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;
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post by elGringo »

As I understand, somewhere here url is not assigned again

Code: Select all

 RichViewEdit1.OnImportPicture := RVAControlPanel1.DoImportPicture;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post by Sergey Tkachenko »

Include rvoAssignImageFileNames in RichViewEdit1.Options.
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post by elGringo »

Perfect! It works, just works !!! Thank you very much, Sergey!!!
elGringo
Posts: 49
Joined: Thu Oct 08, 2015 7:01 pm

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

Post 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;
Post Reply