1c data storage temporary storage. Temporary storage. How are they called?

Almost any information can be stored in a value store, e.g.

... pictures (photos):

CurrentImage.Object = SprFabric.Link; CurrentImage.DataType = Enumerations.Types of Additional Information of Objects.Image; Storage = NewValueStorage(NewPicture, NewDataCompression()); CurrentImage.Storage = Storage.Get();

// in this place it displays everything... Form Elements.PictureField1.Picture = Storage.Get(); CurrentImage.Write();

...spreadsheet document:

TabDoc=New TabularDocument; TabDoc.Output(FormElements.TabularDocumentField1); Storage=NewValueStorage(TabDoc); Write();

End of Procedure

Procedure RestoreFromStoragePress(Element)

TabDoc=Storage.Get(); If TabDoc<>Undefined ThenFormElements.TabularDocumentField1.Output(TabDoc); endIf;

End of Procedure

...arbitrary files (binary data):

XZ = NewValueStorage(NewBinaryData(file));

Eight supports compression of data placed in storage:

XZ = NewValueStorage(NewBinaryData(file),NewDataCompression(9));

... external processing and reporting:

Procedure LoadProcessingIntoStorage(PropsStorageType)

CompressionRate = NewDataCompression(9); //9 maximum PropsStorageType = New StorageValues(New BinaryData("c:\reports\report.epf", Compression Rate));

End of Procedure

Procedure StartProcessingFromStorage(PropsStorageType)

TemporaryFileName = TemporaryFileDirectory()+"report.epf"; BinaryData = PropsStorageType.Get(); BinaryData.Write(TemporaryFileName); ExternalProcessing = ExternalProcessing.Create(TemporaryFileName); ExternalProcessing.GetForm().Open();

End of Procedure

Working with storage

If it was Binary Data, then it can be restored from the value store using the Get method and written to a file using the Write() method.

If TypeValue(Storage)<>Type("BinaryData") Then

BinaryData = Storage.Get();

BinaryData = Storage;

endIf; BinaryData.Write(FileName);

If it was, for example, a Word document (doc file, or other registered file type), then it can be opened like this:

LaunchApplication(FileName);

To clear a field of type Value Storage, you need to assign it Undefined:

PropsStorage = Undefined;

Working with files and pictures in the built-in language 1C:Enterprise 8

Purpose

The managed application implements a new mechanism for working with files. It provides file exchange between the infobase and the client application. The peculiarity of this mechanism is that it is designed for use in a thin client and a Web client and is designed taking into account the restrictions on working with files imposed by Web browsers.

The mechanism is a set of methods that can be used to place data stored locally on the user's computer in a temporary storage of the information base, transfer this information from the temporary storage to the database, and receive it back to the user's computer. The most common application problems solved by this mechanism are the storage of accompanying information, for example, images of goods, documents related to contracts, etc.

Method Scope

Temporary storage

Temporary storage is a specialized area of ​​the information base in which binary data can be placed. The main purpose is the temporary storage of information during client-server interaction before it is transferred to the database.

The need for temporary storage arises because the web browser operating model requires that the user-selected file be transferred directly to the server without the possibility of storing it on the client. When a file is transferred, it is placed in temporary storage and can then be used when writing an object to the database.

The most typical application task solved by temporary storage is providing access to files or pictures before the object is recorded in the information base, for example, in the form of an element.

A file or binary data placed in storage is identified by a unique address, which can later be used in write, read, or delete operations. This address is given by methods for writing a file to temporary storage. A separate method in the built-in language allows you to determine whether the passed address is an address pointing to data in temporary storage.

Information base

The mechanism allows you to access binary data stored in attributes of the Value Storage type.

As in the case of temporary storage, access to information is possible through a special address. You can get it through a special method by passing a link to an object or an information register entry key, and the name of the attribute. In the case of a tabular part, it is additionally required to transfer the row index of the tabular part.

Methods for working with files have limitations when working with infobase details. For them, unlike temporary storage, only reading information is available, but not writing or deleting it.

Description of methods for working with files

Saving data to temporary storage

The most typical scenario for using this mechanism involves initially placing user data in temporary storage. There are two methods for this: PlaceFile() and PlaceFileInTemporaryStorage().

The first method, PlaceFile(), places a file from the local file system into temporary storage. The method can accept a target address in storage. If it is not defined or is an empty string, then a new file will be created and the method will return its address through the corresponding parameter.

If the parameter that determines the interactive mode of operation is True, then the method will display a standard file selection dialog box in which you can select a file to place in storage. In this case, the method will also return the address of the selected file.

As a result, the method returns False if the user interactively refused to perform an operation in the file selection dialog. The method is only available on the client.

The second method, PlaceFileInTemporaryStorage(), is similar to the previous one, except that it is available on the server, and the data to be written to temporary storage is represented not as a path in the file system, but as a variable of type BinaryData. Likewise, if no target address is specified, a new file is created in the storage. Its address is returned as the result of the function.

Retrieving a file from temporary storage

When writing an object to the infobase, you may need to extract data from temporary storage and place it, for example, in an attribute. There is a corresponding server method for this - GetFileFromTemporaryStorage(). This method retrieves data from temporary storage and returns it as a result. To do this, you need to specify the address in temporary storage. This address is returned by the above-described methods PlaceFile() and PlaceFileInTemporaryStorage() if they are executed successfully.

Deleting a file from temporary storage

After the data is saved in the details, the file in temporary storage can be deleted. For this purpose, there is a method DeleteFileFromTemporaryStorage(), which deletes a file from temporary storage. The method takes as a parameter the address of a file in temporary storage. Available on the server.

Checking the address for temporary storage

The file address can indicate both temporary storage and details in the infobase. To check its type, there is a method This isTemporaryStorageAddress().

It checks that the passed address is an address pointing to the store. Returns True if the address points to temporary storage. The method is available on the server.

Receiving the props address

After the data is placed in the details in the infobase, you may need to access it using file methods.

But before you receive data, for example from a property, you need to get the address of this property. For this purpose, there is a method GetFileAddressInInformationBase().

Its purpose is to return the file address in the infobase according to the original parameters. To do this, you need to pass the object key (this can be either a link to the object or an information register entry key) and the name of the attribute. If you need to get the address of a file stored in a tabular part attribute, before the attribute name in the parameter specifying the attribute name, you need to add the name of the tabular part and a dot “.”. The method is available on both the client and the server.

Retrieving a file from the infobase

The GetFile() method receives a file from the infobase and saves it to the user's local file system. The first parameter specifies the address of the file in the props or temporary file storage. The second parameter specifies the destination location of the resulting file. In non-interactive mode, you must specify the path. In interactive mode, the parameter is optional.

By default, the method is executed in interactive mode, that is, the last parameter is True. This means that a dialog box is displayed in which you can specify an action with the received file: run it or save it to a user-specified location. If interactive mode is active and the Target disk file path parameter is not specified, the file open operation is not available. Returns a boolean value. False means the user chose to cancel the operation in the interactive save file dialog box.

Example of using file methods

// Receiving a file from disk in interactive mode // and placing it in temporary storage &On the Client Procedure SelectDiskFileAndWrite()

Variable SelectedName; VariableTemporaryStorageAddress; If PutFile(TemporaryStorageAddress, SelectedName, True) Then Object.FileName = SelectedName; PlaceObjectFile(TemporaryStorageAddress); endIf;

End of Procedure

// Copying a file from temporary storage to a directory // attribute, recording an object, deleting a file from temporary // storage &On the Server Procedure Place Object File (Temporary Storage Address)

Directory Element = Form AttributesValue("Object"); BinaryData = GetFileFromTemporaryStorage(TemporaryStorageAddress); Directory Element.File Data = NewValueStorage(BinaryData); FilePathOnDisk = New File(DirectoryItem.FileName); Directory Item.FileName = FilePathOnDisk.Name; Directory element.Write(); Modified = False; DeleteFileFromTemporaryStorage(TemporaryStorageAddress); ValueВFormAttributes(Directory Element, "Object");

End of Procedure

// Reading a file from the props and saving it // on the local disk in interactive mode &On the Client Procedure ReadFileAndSaveToDisk()

Address = GetFileAddressInInformationBase(Object.Link, "FileData"); GetFile(Address, Object.FileName, True);

End of Procedure

Support for addresses in the picture field

The Picture Field control supports displaying a picture specified by the address of a file in temporary storage or in a database.

To do this, you must set a string type attribute in the Data property of the form element. The value of this attribute will be interpreted as the address of the picture.

Example // Binding the image field to the image address in temporary // storage. AddressPictures form details of string type

PlaceFile(PictureAddress,True)

Picture.Data = AddressPictures

Limitations when working with the Web client

The operation of the described mechanism when using the Web client has some limitations. These restrictions are related to the browser's security model. So, for example, the client cannot independently save a file to the local file system, that is, only the interactive version of the client methods PlaceFile() and GetFile() is available. An exception is thrown when attempting to use non-interactive mode. The dialog boxes that appear interactively are specific to your browser type.

Features when working with Value Storage on the Client

Problem:

When a Document has an attribute of the Value Storage type in the tabular section, it slows down the opening of the document form if this attribute contains large data.

Supposed reason:

Perhaps, when opening a form, it is not the link to the data located in the Value Store that is sent to the client, but the data itself.

Solution

  • In the properties of the form's table attribute there is a flag "Always use". If it is set, the contents of the field are always transferred between the server and the client - for example, when opening a form. This flag must be disabled, but this must be taken into account in the code, since by default there will be no value for this field on the client. An example can be found in 1C:Archive.

It's even better to use temporary storage to transfer files between client and server.

Material updated to match Drupal 8.7.0+

Temp store(temporary storage) - allows you to temporarily store any data. This is a kind of data storage in $_SESSION, since this storage is usually associated with a certain user. But it doesn’t use $_SESSION and stores everything inside the system (in the database).

The core has two services for temporary storage, tempstore.private and tempstore.shared. They work identically, but private always stores data for a specific user. That is, calling one key from a private storage will return different data for each user. Shared is accessible from each user.

The scope of application of these services and their storage can be very vast. For example, store some temporary values ​​of forms, and if the user has not saved them, they can be restored from this storage, for example, for some REST forms, and even suitable for regular ones. In general, what you have enough imagination or tasks for. For example, this can be used for some forms controlled outside of Drupal, for example in React or Vue.

Values ​​in these storages live by default for 604800 seconds (1 week), after which they are automatically deleted.

To change this value. You will need to connect, for example, sites/default/services.yml and redefine it:

Parameters: # 10 seconds tempstore.expire: 10

But this, for good reason, shouldn’t happen.

Let's look at the capabilities of each storage device; although they are similar, they are slightly different.

tempstore.private - private storage

This storage is private for each user.

tempstore.shared - shared storage

This storage is shared and may contain data common to all users.

The repository has the following methods:

  • get($key) : Retrieves a value from the store by its key. If there is no data, it will return NULL, if there is, it will return a value.
  • getIfOwner($key) : Retrieves a value from the store by its key. If there is no data or the data was not written under the current user, it will return NULL, if there is and were written under the current user, it will return the value.
  • setIfNotExists($key, $value) : Writes the value $value under the key $key to storage only if there is currently no data for that key. Returns TRUE if recorded, FALSE if data has already been recorded.
  • setIfOwner($key, $value) : Writes the value $value under key $key to storage only if there is currently no data or the owner of the actual data is the current user.
  • set($key, $value) : Writes the value $value under the key $key to storage.
  • getMetadata($key) : Returns metadata for a specific $key , without data. This is an object containing the owner property, which stores the value, who owns the value, and the updated property - the Unix time stamp of the time this value was written.
  • delete($key) : Deletes data associated with the given $key from storage.
  • deleteIfOwner($key) : Deletes data associated with the given $key from storage, only if the data belongs to the current user.

How are they called?

Small examples of how to call them.

The first step is to obtain the tempstore of the required storage, then from the storage a “collection” is obtained, where the data is already stored under the necessary keys. As a rule, the name of the "collection" is equal to the name of the module.

Use Drupal\Core\TempStore\PrivateTempStoreFactory; use Drupal\Core\TempStore\SharedTempStoreFactory; /** @var PrivateTempStoreFactory $private_tempstore */ $private_tempstore = \Drupal::service("tempstore.private"); $my_private_storage = $private_tempstore->get("dummy"); $my_private_storage->set("username", "Drupal"); /** @var SharedTempStoreFactory $shared_tempstore */ $shared_tempstore = \Drupal::service("tempstore.shared"); $my_shared_storage = $shared_tempstore->get("dummy"); $my_shared_storage->set("username", "Drupal");

Example

In the example, we will create a form on the /temp-store-form page with two fields, one of which will store the message in private storage, and the other in public.

Create a form:

Src/FormWithTempStore.php

privateTempStore = $private_temp_store->get("dummy"); $this->sharedTempStore = $shared_temp_store->get("dummy"); ) /** * (@inheritdoc) */ public static function create(ContainerInterface $container) ( return new static($container->get("tempstore.private"), $container->get("tempstore.shared") ); ) /** * (@inheritdoc) */ public function getFormId() ( return "form_with_temp_store"; ) /** * (@inheritdoc) */ public function buildForm(array $form, FormStateInterface $form_state) ( $form ["private_message"] = [ "#type" => "textarea", "#title" => $this->t("Private message"), "#required" => TRUE, "#description" => $ this->t("This value will be private for each user."), "#default_value" => $this->privateTempStore->get("message"), ]; $form["shared_message"] = [ " #type" => "textarea", "#title" => $this->t("Shared message"), "#required" => TRUE, "#description" => $this->t("This value will be shared for all users."), "#default_value" => $this->sharedTempStore->get("message"), ]; $form["actions"] = ["#type" => "actions" ]; $form["actions"]["submit"] = [ "#type" => "submit", "#value" => $this->t("Save"), ]; return $form; ) /** * (@inheritdoc) */ public function submitForm(array &$form, FormStateInterface $form_state) ( $this->privateTempStore->set("message", $form_state->getValue("private_message")); $this->sharedTempStore->set("message", $form_state->getValue("shared_message")); ) )

Print (Ctrl+P)

1C:Enterprise has a mechanism for working with temporary storage that provides storage of some session-related data.
In addition, a mechanism for working with files has been implemented, which ensures the exchange of files between the infobase and the client application. The peculiarity of this mechanism is that it is designed for use in a thin client and a web client and is designed taking into account the restrictions on working with files imposed by web browsers.

Temporary storage

This is a specialized store of information into which a value can be placed. The main purpose is the temporary storage of information during client-server interaction before it is transferred to the database. The temporary storage mechanism, together with the file handling mechanism, provides a set that can be used to place data stored locally on the user’s computer in the temporary storage of the information base, transfer this information from the temporary storage to the database, and get it back to the user’s computer. The most common application problems solved by these mechanisms are the storage of accompanying information, for example, images of goods, documents related to contracts, etc. Mechanisms for temporary storage and working with files are often used together, but can also be used separately.
The need for temporary storage arises, for example, because the web browser model requires that a user-selected file be transferred directly to the server without the ability to store it on the client. When a file is transferred, it is placed in temporary storage and can then be used when writing an object to the database.
You can use temporary storage as a universal storage with controlled data lifetime:

1. If, when placing data in temporary storage, the data was bound to a certain form, then the lifetime of the stored data depends on the life expectancy of the form to which the data is bound. When you delete a form object, the temporary storage will be cleared of all information associated with it.

2. If, when placing data in temporary storage, the binding to the form was not completed, then the temporary storage will be cleared in the following cases:

  • The next time you request the form.
  • On the next server call from the client common module.
  • For contextual and non-contextual client calls from the form.
  • When called server-side from a command module. If a server call is made to place a value in temporary storage, no cleanup is performed. Cleanup occurs after the call has completed its work.

That is, you can put one or more values ​​in temporary storage, and use this value in the next call. However, after use and before the server call is completed, the placed value will be automatically removed.

The most typical application problem solved by temporary storage is providing access to files or pictures before the object is recorded in the information base, for example, in the form of an element. When organizing such access, it is recommended to transfer data from client computers to the server exactly as files, without prior “conversion” into a text document, spreadsheet document and similar formats of the 1C:Enterprise system. It is recommended to transfer the file to the server side and, on the server side, load the file data into the desired
format of the 1C:Enterprise system.
Data placed in storage is identified by a unique address, which can later be used in write, read or delete operations. This address is given by methods for writing a value to temporary storage. A separate method in the built-in language allows you to determine whether the passed address is an address pointing to data in temporary storage.
Temporary storage created in one session is not accessible from another session. An exception is the ability to transfer data from a background job to the session that initiated the background job using temporary storage.

Burty . The most acceptable way to store potatoes, root vegetables and white cabbage is bottling. A pile is an oblong embankment, inclined on both sides, and covered with insulating material on top. It is made to store the harvest for one season. Burts can be ground, when potatoes are poured onto a flat surface, and semi-ground, when shallow pits are dug. Popunautny (buried) pile. For such a pile, a pit with a depth of 25 cm is dug in the direction from north to south. The best width of the pit for seed potatoes is 170-200 cm. For short-term storage of healthy potatoes, you can make a wider embankment (up to 4 m). The length of the pit can be arbitrary, but, nevertheless, it is better when it is no more than 20-25 m. The height of the embankment of the pile, with its width at the base of 2 m, can be 90-100 cm. Typically, potatoes are stored in several piles on one site. The drilling site is placed near potato growing areas in a place that is not flooded by rain and melt water, not far from the road. A ventilation duct 20-25 cm wide and deep is dug along the central axis of the pit. It extends beyond the pit and is 25 cm longer than the covering at the end of the collar. The part of the channel extending beyond the boundaries of the pit is tightly covered with boards on top so that no earth gets into the pit and the channel. In ground collars, the ventilation duct is placed directly on the surface of the ground and is made in the form of a lattice tent made up of separate one and a half meter sections. To prevent straw and earth from getting into the ventilation duct, its ends are made without gaps. To cover the ventilation ducts, lattice sections 1.5 m long and 0.5 m wide are prepared in advance. The section consists of slats 2-3 cm wide and 2-2.5 cm gaps between them. The sections are laid on the ventilation duct and fastened to each other. The resulting continuous ventilation grille covers the part of the channel located under the product. During the formation of a mound of potatoes or other products, a collar thermometer or specially made tetrahedral tube-cases with an internal cross-section of 3x3 cm are placed inside, into which thermometers are inserted at the end of the rod. The collars are ventilated through a ridge and a ventilation duct. The piles are covered with straw and earth. Full-thickness straw is laid in a dense layer from bottom to top so that the crest of the pile overlaps. After this, the pile is sprinkled with a thin layer of earth on the sides. The ridge of the pile remains under straw cover until the first frost. In rainy weather, it is temporarily covered with roofing felt or plastic film. When cooling the potatoes to +4°C before the onset of stable frosts, the ventilation ducts are tightly covered with straw, and the pile is completely covered with earth. If the temperature in the piles drops below +1°C, the piles are additionally covered with heat-insulating materials - peat, straw, straw manure or snow. In case of heavy snowfalls, leading to excessive cover of the piles, they are periodically cleared of snow.

Trench storage . This storage method requires 2 times less straw or other heat-insulating materials than when storing in piles. Trenches are used when groundwater is deep. The depth and width of the trench is from 60-80 cm (in the southern regions) to 1.5-2 m (in Siberia). The trenches are covered with a layer of straw on top: in the central regions it is 30-40 cm, in Siberia - up to 70 cm. Then a layer of earth is poured (from 40 to 70 cm depending on the zone). Typically, different types of trenches are used: shallow, deep with ventilation ducts, with a layer of soil and without a layer, and ordinary. Trenches and piles are equipped with (natural) simple ventilation. Its main purpose is cooling potatoes and vegetables in the autumn. The principle of operation of supply and exhaust ventilation is based on the difference in air pressure, i.e. on the draft of air movement upward due to the difference in temperature in the stack of products and outside. Warm air, being lighter, leaves through the exhaust pipe, and cold air enters through the supply duct. The ventilation system consists of supply and exhaust ducts. The inlet channel runs in the middle of the base of the collar; there are exits to the outside at the end ends. In piles with potatoes and root vegetables, they make a groove with a cross-section of 20x20 cm or 30x30 cm, covered with lattice boards, transverse slats or brushwood, so that individual copies of the product do not fall through. Through this channel, colder outside air flows into the stack by gravity. The heated air from the stack is removed through exhaust ducts (pipes). They are tetrahedral boxes made of boards with a cross-section of 20x20 cm or 15x15 cm. In the lower part, passing through the layer of vegetables, they are made lattice, and in the upper part, passing through the shelter, they are solid so that soil does not fall into them. A canopy is installed on top of them to protect the products from rainwater. Exhaust pipes, depending on the characteristics and quality of the vegetables stored for storage, are installed every 2-4 m along the length of the pile. One of the disadvantages of vertical exhaust pipes is that warm and humid air is removed only from the adjacent areas of the stack, and remote areas are hardly cooled. Water flows in near the exhaust pipes, sweating and freezing the products, since here the shelter is less dense and reliable. Therefore, ridge exhaust ventilation is used. When storing vegetables in dry, cool weather, the crest of the trench is covered only with straw, through which warm air is removed. However, such conditions are rare; the weather is often rainy in the fall. In such cases, a horizontal exhaust duct is installed - boards knocked together at an angle of 90°, which are laid on a stack of vegetables with an exit at the ends to the outside. In this case, the trench along the ridge can be immediately covered with straw and earth, without fear of the straw getting wet and the product freezing. You just need to close the end holes in time. The advantage of a horizontal ridge exhaust duct over vertical exhaust ventilation pipes is also that in this case warm and moist air is removed evenly from the entire stack of products.

Pit. The simplest storage is an earthen pit - intended for storing, most often, a small batch of potatoes, and occasionally root crops. It is dug on an elevated area with a low groundwater level. Depending on the density of the soil, it is dug with straight or inclined walls. The most acceptable pit shape is round, however, sometimes they are made rectangular. A hole is dug in dense clay soil, shaped like a jug. It is not recommended to do this in sandy soil, as it will collapse. Dig a hole as follows: draw a circle with a diameter of 1 m and dig out the neck of the jug, then, digging deeper, gradually expand the hole to a width of 2-2.5 m in diameter. The depth of the pit-jug should be 1.5-2 m. To prevent melt water from entering the pit, a roller of removed clay is laid around the opening of the neck. Such a storage facility is covered with a lid placed at a slope to allow rainwater to roll off. A well-made pit jug lasts 30-40 years without repair. In winter, it will maintain a more constant temperature and humidity than in a regular basement. Potatoes in such a pit do not sweat and do not germinate for a long time. Potatoes are stored in small pits without ventilation. In large ones, a ventilation pipe is installed from boards or four stakes driven into the bottom of the pit and wrapped with a straw cord. Potatoes are lowered into the hole using a bucket. Two ropes are tied to the bucket: one to the handle, and the other to the bottom. After the bucket reaches the floor, pull the rope attached to the bottom. At the same time, the bucket tips over and the potatoes spill out. Tubers are not injured with this method of backfilling. After filling the pit-jug with potatoes, the neck is closed with straw and a lid. During the first two weeks, potatoes release a lot of moisture when they breathe, so the layer of straw should not be thick. Later, the layer is adjusted to 50-70 cm, depending on local winter conditions.

Print (Ctrl+P)

This section describes the most common uses of the mechanism for working with temporary storage and files.

Saving data from a file to temporary storage

Placement of one file

The PlaceFile() method places a file from the local file system into temporary storage. The method can accept an address in temporary storage where the file should be saved. If the address is not defined or is an empty string, then a new address will be created and the method will return it through a special parameter.
Note. The amount of data moved between the client and server in one call to the PutFile() method
If the parameter that determines the interactive mode of operation is True, then the method will display a standard file selection dialog box in which you can select a file to place in storage. In this case, the method will also return the address of the selected file.
The method returns False as a result if the user interactively refused to perform an operation in the file selection dialog.

Placing a set of files

Method PlaceFiles() places multiple files into temporary storage in one call. There are several different ways to use this method:
● pre-generate a list of files to be added, for example, when you have previously selected the files that need to be placed in the information base;
● pass a file search mask to the method, for example, when you want to place all files of a certain type, for example, all pictures, into the information database;
● pass a previously prepared object to the method File Selection Dialog in file opening mode.
After finishing its work, the method can return a list of actually added files.

// FileList – attribute of the form of the ValueList type,
// containing a list of added files
FileArray = New Array;
For each Element of the List from the List of Files Cycle
FileArray.Add(NewDescriptionofTransferFile(ListElement,));
EndCycle;
PlacedFiles= New Array;
Result = PlaceFiles(ArrayFiles, PlacedFiles, False, UniqueIdentifier);

Note 1: To use the method PlaceFiles() The web client requires the connection of a file processing extension.
Note 2: Amount of data moved between client and server per method call PlaceFiles(), should not exceed 4 Gb (in serialized form).

Placing data in temporary storage

The method is similar to the PlaceFile() method, except that the data to be written to temporary storage
are not represented as a path in the file system, but as a value. Likewise, if no existing address is specified in temporary storage, a new address is created. The address is returned as the result of the function. As with files, the posted data must belong to some form and is automatically deleted after it is deleted.
Note. Amount of data moved between client and server per method call PlaceInTemporaryStorage(), should not exceed 4 Gb (in serialized form).
Attention! When placed in temporary storage, the value is not actually serialized. A reference to the value is placed and stored in the cache for 20 minutes. After this period, the value is serialized, written to disk (session data storage), and removed from the cache.

Retrieving data from temporary storage

When writing an object to an infobase, you may need to extract data from temporary storage and place it, for example, in an infobase object attribute. There is a special method for this - GetFromTemporaryStorage(). This method retrieves data from temporary storage and returns it as the execution result. To receive data, you must indicate the address in temporary
storage. This address is returned by methods for placing data in temporary storage if they are successful (see previous sections).
Attention! When retrieving a value from temporary storage on the server, you should take into account that it is obtained by reference. In reality, this link points to a value that is stored in the cache. Within 20 minutes, from the moment it was placed in storage or from the moment it was last accessed, the value will be stored in the cache, and then written to disk and deleted from the cache. The next time the value is accessed, it is loaded from disk and placed back into the cache.
After deserialization and restoration of values ​​from temporary storage, references are not restored. The cache value is restored from disk. But after serialization/deserialization, it is impossible to restore references to other objects inside the value.

Deleting data from temporary storage

After the data is saved in the infobase object attribute, the data in the temporary storage can be deleted. There is a method for this
RemoveFromTemporaryStorage(), which performs the removal. The method takes an address in temporary storage as a parameter.

Checking the address for temporary storage

The address can indicate both temporary storage and details in the information base. There is a method to check its type
This isTemporaryStorageAddress(). It checks that the passed address is an address pointing to the store. Returns True if the address points to temporary storage.

Receiving the props address

After the data is placed in the infobase object attribute, you may need to access it using file methods.
But before you receive data, for example from a property, you need to get the address of this property. There is a method for this GetNavigationLink().

It can return the address of the value in the infobase based on the original parameters. To do this, you need to pass the object key (this could be
both a link to the object and the entry key of the information register) and the name of the attribute. If you need to get the address of the value stored in the attribute
tabular part, then to the attribute name in the parameter specifying the attribute name, you must add the name of the tabular part and a dot “.”. For example: Products.Image

Retrieving a file from the infobase

Receiving one file

The GetFile() method receives a file from the infobase and saves it to the user's local file system. The first parameter specifies the file address in the infobase object attribute or in the temporary file storage. Saving will not occur if the user on whose behalf the operation is performed does not have the View right to the details of the infobase object. The second parameter determines the location where the resulting file is saved. In non-interactive mode, you must specify the path. In interactive mode the parameter is
optional.
By default, the method is executed interactively. This means that a dialog box will be generated in which you can specify an action with the received file: run it or save it to a user-specified location in the file system. If interactive mode is selected and the File name option is not specified, the file open operation is not available. The method returns a Boolean value. False means the user chose to cancel the operation in the interactive save file dialog box.

Receiving a set of files

The GetFiles() method allows you to receive and save several files stored in the infobase in the user's local file system. The list of uploaded files is passed as a parameter.

// FileList – a list of values ​​containing links to elements
// directory in which the uploaded files are located
// The list of values ​​representation is the name of the file being uploaded
FileArray = New Array;
For each Element of the List from the List of Files Cycle
File = New File(String(ListElement.Value));
ReceiveFile = New Description of the transmitted file;
ReceiveFile.Name = ListElement.View;
ReceiveFile.Storage= P getNavigationLink(ListItem.Value, “Data”);
FileArray.Add(ReceivingFile);
EndCycle;
Received Files= New Array;
Result = ReceiveFiles(FilesArray, ReceivedFiles, UploadedFilesPath, False);
If NOT Result Then
Message = New Message to User;
Message.Text = “Error receiving files!”;
Message.Message();
EndIf ;

After finishing, the method can return a list of actually downloaded files, indicating the full name of each saved file.
NOTE. To use the GetFiles() method in the web client, you need to connect the file extension. If the property Object name Description of the transmitted file contains the absolute path to the file, the file will be saved to this path, regardless of the parameter File Location.
The File Location parameter can be either a path in the local file system or a File Selection Dialog object in the mode of selecting a directory or saving files. If the parameter value File Location object specified File Selection Dialog in mode
saving files, then:

● the dialog will be called for each transferred file, except for those files for which the Transmitted File Description object name property contains an absolute path;
● the value of the object Name of the Description of the Transmitted File property will be used as the initial file name in the dialog;
● if refusal to save is selected for any file, then the Name of the object Description of the Transferred File property will contain an empty string;
● the GetFiles() method will return the value True if at least one file was received successfully;
● it should be taken into account that the files are actually received after the user answers questions about specifying the name and path
all received files;
● if the user on whose behalf the GetFile() method is executed does not have the View right to at least one attribute of the infobase object from which files are retrieved, the entire operation will fail.
Example:

TransferredFiles = New Array;
Description = New Description of the transmitted file(“Description”, FileAddress);
Transferred Files.Add(Description );
FileSelect = New FileSelectionDialog(FileSelectionDialogMode.Save);
FileSelect.Header= “Save archive”;
File Selection.Extension= “zip”;
FileSelect.Filter= “Archive(*.zip)|*.zip|All files|*.*”;
FileSelect.FilterIndex = 0;
ReceiveFiles(TransferFiles, SelectFile, False);

If the interactive mode for selecting the directory for saving files is selected, the web client will additionally request permission to save files specified with absolute paths. In the case of non-interactive saving (the path to the directory is specified in the corresponding parameter), the request will be executed for the entire list of saved files.

Example of using file methods

// Retrieving a file from disk interactively
// and placing it in temporary storage.
&OnClient
Procedure SelectDiskFileIWrite()
Variable SelectedName;
Perem TemporaryStorageAddress;
NewObject = Object.Link.Empty();
If PlaceFile(TemporaryStorageAddress, “”, SelectedName, True) Then
Object.FileName = SelectedName;
PlaceObjectFile(TemporaryStorageAddress);
endIf;
End of Procedure
// Copying a file from temporary storage to props
// directory, writing an object, deleting a file from temporary
// storage.
&On server
Procedure PlaceObjectFile(TemporaryStorageAddress)
Directory Element = Form AttributesValue(“Object”);
BinaryData = GetFromTemporaryStorage(TemporaryStorageAddress);
Directory Element.File Data= New StorageValues(BinaryData, NewDataCompression()) ;
File = New File(Directory Item.FileName);
Directory Item.FileName = File.Name;
Directory element.Write();
Modified = False;
DeleteFromTemporaryStorage(TemporaryStorageAddress);
ValueВFormAttributes(Directory Element, “Object”);
End of Procedure
// Read the file from the props and save it
// on the local disk in interactive mode.
&OnClient
Procedure ReadFileAndSaveToDisk()
Address = GetNavigationLink(Object.Link,"FileData");
GetFile(Address, Object.FileName, True);
End of Procedure

Permission to perform a group of file operations

When performing some operations in the web client, you may need to obtain permission for multiple file operations.
For example, you need to retrieve a document from an infobase and then open the saved document using the associated application.
To perform this operation, you will need to answer the question about saving the document and the question about the need to run it. If there are more operations, the user will also have more questions.
To reduce the number of questions, you can use the method. When using this method
The user is shown a list of all the operations that are planned to be performed and is asked to allow the group of operations to be performed. If the user has allowed execution, then the requested operations will be performed without additional requests to the user. If permission is not granted, operations will proceed as normal: one request per operation.
NOTE. To use the method RequestUserPermission() In the web client you need to enable the file management extension.
Let's look at an example of using the method:

If ConnectExtensionWorking With Files() Then
Link = GetNavigationLink(Object.Link, “FileData”);
// Formation of a description of the transferred files (in this case there is only one file)
Transferred Files= New Array;
Description = New Description of the Transferred File (Object. FileName, Link);
TransferredFiles.Add(Description);
// Prepare an object to receive information about received files
Transferred Files= New Array;

// Define other method parameters
DirectorySave= “c:\temp”;
Interactive = False ;
Transmitted FileName = Saving Directory + “\” + Object.FileName;
// Prepare a description of methods for obtaining permissions
Methods = New Array;

Methods.Add(“GetFiles”);
Methods.Add(TransferFiles);
Methods.Add(TransferredFiles);
Methods.Add(SaveDirectory);
Methods.Add(Interactive);
Methods.Add(New Array);
Methods.Add(“RunApplication”);
Methods.Add(TransferredFileName);
If not RequestUserPermission(Methods) Then
Warning("The user has denied permission.");
Return;
endIf;
GetFiles(TransferFiles, TransmittedFiles, SavingDirectory, Interactive);
RunApplication(TransferredFileName);
Otherwise
Warning("Execution is not supported. The file extension is not installed.");
endIf;

Several features of the method should be noted RequestUserPermission().

1. Permission is requested only for the following methods:

GetFiles()/StartGettingFiles(),
● PlaceFiles()/StartPlaceFiles(),
● FindFiles()/StartSearchFiles(),
● CopyFile()/StartCopyFile(),
● MoveFile()/StartMovingFile(),
●DeleteFiles()/StartDeleteFiles(),
● CreateDirectory()/StartCreatingDirectory(),
● LaunchApplication()/StartRunApplication().

2. Permission is requested for a specific set of method parameters. If, during the actual execution of a file manipulation method, the parameter values ​​differ from those for which permission was obtained, this permission will not be valid and the user will receive a separate request to confirm the operation.

3. If you need to perform two (or more) identical operations with files (even with the same set of parameters), you should specify the appropriate number of elements in the method parameters array RequestUserPermission(). For example, if you need to get the same file from the infobase twice and place it in a fixed location in the file system, you should request permission
for two operations.

4. If permission is requested for an operation that performs an interactive operation (for example, the GetFiles() function, an object is passed as a parameter File Selection Dialog), then such an operation is excluded from the request.

Granted permissions are retained either until the authorized call is executed or until the built-in language finishes executing.
NOTE. In thick and thin clients RequestUserPermission() The method always returns True, without user interaction.

Working with temporary storage in a background job

The mechanism for working with temporary storage has the ability to transfer data from a background job to the session that initiated the background job.
For such a transfer, you should place an empty value in temporary storage in the parent session (using the method PlaceInTemporaryStorage()), specifying any identifier of the temporary storage being created (Address parameter). Then pass the received address to the background job through the background job parameters. Further, if in a background job this address is used as the value of the Method Address parameter PlaceInTemporaryStorage(), then the result will be copied to the session from which the background job was launched.
Data placed in temporary storage in a background job will not be accessible from the parent session until the background job completes.

Support for addresses in the picture field

The View Field form element The Picture field supports displaying a picture specified by the address of a value (which can be a picture or binary data) in temporary storage or a database.
To do this, you must set a string type attribute in the Data property of the form element. The value of this attribute will be interpreted as the address of the picture.

// Example 1
// Binding the image field to the image address in temporary
// storage. AddressPictures – string type form details
PlaceFile(ImageAddress, InitialName, SelectedName, True, UniqueIdentifier);
// Example 2
// Obtaining the address of the image from the object attribute
// information base
FilePictures = Object.FilePictures;
If Not PictureFile.Empty() Then
ImageAddress = GetNavigationLink(ImageFile, “FileData”);
Otherwise
ImageAddress = “”;
Endless;

Access to standard directories

When using the system, some space is required in the file system where various file data can be stored, which, on the one hand, is temporary, and on the other hand, must be stored for quite a long time. Such files include drafts for document management systems, external components running on the client computer side, etc.
A special directory is intended for storing such files, which is tied to a specific user of a specific information base.
The same user working with two infobases will have access to two different directories for storing user data. The location of this directory is determined using the method WorkUserDataDirectory(). If the directory does not exist, it is created the first time it is accessed. If the directory cannot be created, the system throws an exception.
NOTE. The UserDataWorkDirectory() method is not available on the server side.
The operating system has a special directory allocated for permanent storage of user data. It could be some
reports, printed forms of documents, etc. Data is placed in this directory, which can later be sent to external
to consumers. The DocumentDirectory() method is used to access this directory. The physical location of the directory varies depending on the operating system.
system where the application is executed and is listed in the syntax assistant.