The 1C:Enterprise developers forum

#1
People who like this: 0 Yes / 0 No
Active user
Rating: 3
Joined: Sep 2, 2013
Company:

Hi,

How can I get the html saved in ValueStorage? I want to get HTML and display it in preview.

I tried these solutions:

Code
   //none works
   address = PutToTempStorage(ObjectValue.FileStorage.Get(), UUID);
   address = GetURL(Object.Ref, "FileStorage");
   address = ObjectValue.FileStorage.Get();
   
   Text = New TextReader(address, TextEncoding.UTF8);
   HTMLText = Text.Read();   
   Object.Preview = HTMLText;


Nothing works... but a test like this works:

Code
Text = New TextReader("c:/myfile.html", TextEncoding.UTF8);


Any ideas, please?

 
#2
People who like this: 1 Yes / 0 No
Active user
Rating: 7
Joined: Sep 26, 2012
Company: individual

In my opinion, You have 2 variants

First you can save full file at ValueStorage, like so:

Code
&AtServer
Procedure SaveFileToStorage()
   binary = new BinaryData("c:\myfile.html");
   lObject = FormAttributeToValue("Object");
   lObject.FileStorage = new ValueStorage(binary);
   lObject.Write();
EndProcedure


and then you need save this file and open then by textreader

Code
&AtServer
Procedure OnCreateAtServer(Cancel, StandardProcessing)
   lObject = FormAttributeToValue("Object");
   binary = lObject.FileStorage.Get();
   If NOT binary = Undefined then
      binary.Write(TempFilesDir() + "temp.html");
      Text = New TextReader(TempFilesDir() + "temp.html", TextEncoding.UTF8);
      Preview = Text.Read();
   endif;
EndProcedure


Or second variant save not file but html code to string attribute of object (if its real)

like so
Code
&AtServer
Procedure SaveHTMLToStorage()
   lObject = FormAttributeToValue("Object");
   Text = New TextReader("c:\myfile.html", TextEncoding.UTF8);
   lObject.FileStorage = Text.Read();
   lObject.Write();
EndProcedure


Code
&AtServer
Procedure OnCreateAtServer(Cancel, StandardProcessing)
   Preview = Object.FileStorage;
EndProcedure

 
#3
People who like this: 0 Yes / 0 No
Active user
Rating: 3
Joined: Sep 2, 2013
Company:

Thank you very much, I'll do it right away :)

 
#4
People who like this: 0 Yes / 0 No
Active user
Rating: 3
Joined: Sep 2, 2013
Company:

I have another problem: what if somebody copy pastes an image fr om a web browser?

The image has in src address like "http://www.somewh ere.com/picture.jpg".

I'm trying to get these pictures but I get the 404 not found error... however the HTML in preview (string field which is displayed as HTML in form) is displaying just fine!

The code I'm trying to use:

Code
   HTMLReader = New HTMLReader;
   HTMLReader.SetString(HTMLText);
   DOMBuilder =  New DOMBuilder;
   HTMLDocument = DOMBuilder.Read(HTMLReader);
      
   ImgItems =  HTMLDocument.GetElementByTagName("img");   
   For  Each Img In ImgItems Do      
      
      If Left(Img.Src, 4) = "http" OR Left(Img.Src, 4) = "HTTP" Then

         FileNumber = Format(CurrentDate(), "DF=""yyyyMMddHHmmss""");
         inputFile= TempFilesDir() + "1Cimage"+FileNumber;
         НТТР = New HTTPConnection(Img.Src); 

         НТТР.Get(Img.Src, inputFile); // Get gives 404 error
                        
         Address = TempFilesDir()+"1Cimage"+FileNumber;
         MessagePictures.Add(Address,"1Cimage"+FileNumber);         
         HTMLText = StrReplace(HTMLText, Img.Src, "1Cimage"+FileNumber);
         
      EndIf;


Any ideas?

 
#5
People who like this: 1 Yes / 0 No
Active user
Rating: 7
Joined: Sep 26, 2012
Company: individual

Try like so

Code
НТТР = New HTTPConnection("somewhere.com"); // only server without http and /...
­
НТТР.Get("/picture.jpg", inputFile); // not sure but try

 
#6
People who like this: 0 Yes / 0 No
Active user
Rating: 3
Joined: Sep 2, 2013
Company:

Hello;

Thank you for hint.
It works! :) ... but only when the target server doesn't have the 301 rewrite rules.

If it has such rules in .htaccess:

Code
RewriteCond %{HTTP_HOST} ^somewhere.com(.*) [NC]
RewriteRule ^(.*)$ http://www.somewhere.com/$1 [R=301,L]


Then doing as you said will output a file with 301 headers "The file has moved". :(
These rules are quite frequent for SEO...

 
#7
People who like this: 0 Yes / 0 No
Active user
Rating: 7
Joined: Sep 26, 2012
Company: individual

And what about:

Code
НТТР = New HTTPConnection("www.somewhere.com");

 
#8
People who like this: 0 Yes / 0 No
Active user
Rating: 3
Joined: Sep 2, 2013
Company:

Strangely, it also gives the 301 redirection!  :o

I guess I'll stick to local files... Unless there's another solution.

Thank you for help and please let me know if you find another way. :)

 
#9
People who like this: 0 Yes / 0 No
Active user
Rating: 7
Joined: Sep 26, 2012
Company: individual

maybe there is next redirection and need find the last server

 
#10
People who like this: 0 Yes / 0 No
Active user
Rating: 3
Joined: Sep 2, 2013
Company:

No, I'm pretty sure that the given .htaccess redirection is the only one, when I removed these lines from .htaccess then the script could get the file without problems.  :cry:

 
Subscribe
Users browsing this topic (guests: 3, registered: 0, hidden: 0)