Catalog with picture (manageable forms)

Since 1C platform release 8.2 the work with pictures is performed with different from the previous platforms method to deal with which without examples is difficult.
The picture as before is stored in the base in attribute with type ValueStorage, but it is impossible to write data in the attribute with this type in normal way, the writing is performed in predefined procedure «BeforeWriteAtServer».

To display the picture, the form item picture field is created the data for which is a form attribute (with type String(0)) which contains the navigation reference to the picture (can be received with function «GetURL») or the address in the temporary repository (func. «PutFile»)

Below there is the code of example part:

&AtClient
Procedure UploadingPicture(Command)
    Var SelectedName,AddressTemporaryStorage;
    If PutFile(AddressTemporaryStorage, "", SelectedName, True, UUID) Then
        AddressPicture = AddressTemporaryStorage;
        Modified = True;
    EndIf;
EndProcedure

&AtServer
Procedure BeforeWriteAtServer(Cancel, CurrentObject, WriteParameters)

    If IsTempStorageURL(AddressPicture) Then
        BinaryData = GetFromTempStorage(AddressPicture);
        CurrentObject.Photo = New ValueStorage(BinaryData, New Deflation());
    EndIf;

EndProcedure

&AtServer
Procedure OnReadAtServer(CurrentObject)

    AddressPicture = GetURL(CurrentObject.Ref, "Photo");

EndProcedure

&AtServer
Procedure OnWriteAtServer(Cancel, CurrentObject, WriteParameters)

    If IsTempStorageURL(AddressPicture) Then
        DeleteFromTempStorage(AddressPicture);
    EndIf;

    AddressPicture = GetURL(CurrentObject.Ref, "Photo");

EndProcedure

In the procedure OnWriteAtServer, at first sight, it is possible to remove the code of deleting from the temporary repository, because the func. PlaceFile is called with parameter UniqueIdentifier of the form, that is, the repository object will exist to the form closure, but it is recommended to release the resources at once (if the user will load the picture and click Write, the form is not closed and an object will exist to the closure).

You can download dump of information base below this publication.

Publications: Catalog with picture (manageable forms)

File: 1Cv8.zip

Click to rate this post!
[Total: 0 Average: 0]

Leave a Reply

Your email address will not be published. Required fields are marked *