the Internet Windows Android

1C Transform a string into binary data. Work with binary data

Binary data in 1C are designed to store the faers of an arbitrary format. With their help, you can:

  • Organize interaction on binary protocol with various devices;
  • Store in the form of the details of the metadata objects of any formats;
  • Convert text data to binary (most often used to send reports);
  • Work with binary data in memory.

What can system can

When working with binary data, the platform 8.3 is able to perform the following actions:

  1. Read and write binary data;
  2. Move data from the client to the server and back using the temporary storage;
  3. Initialize with help binary files object type "picture";
  4. To read them from the worldwide network using the Mailing Objects, NTTr Compound, etc.
  5. Use cryptographic products for encryption and signature of important investments;
  6. Using the "hashized" object, calculate the hash function.

Saving data into props

For example, create a directory in the test configuration.

In fact, use the same reference book for storing information about the nomenclature and binary data of the pictures is a bit incorrect. With sufficiently large amounts of data and heavy large-scale files, unwanted downtime and "brakes" can occur in the system. A separate reference book "Pictures" will be organized much correct from the point of view of the system, the link to which we could set as a type of props.


It is important to note that due to the fact that the requisites of the "repository" type containing binary data are not available in the controlled application mode, the appeal to them is possible only using the props-conformity method.


The message field provides a record of binary data storage data.

Reading data from props

Create a processing that will display the file stored in a binary form in our configuration into a tabular document (it is necessary, let's say to print the logo of the company).


In principle, this is the entire code that we need. Using the operator to get (), we read binary data stored in the appropriate details of the reference book and transmit them to the "picture" object, which will be shown in the upper left cell tabular document Forms (Fig. 9).

Fig.9.

Data conversion

Infrequently, but it happens that when working with non-standard exchanges with external systems You need to convert data from binary format to BASE64 or back.

In most cases, the platform independently converts data if this does not occur, it is necessary to use global translation functions:

  1. Base64 Stroke - translates the specified value in the row of the corresponding encoding;
  2. Base64Ding - makes the reverse transformation.

Optimization of the above code

The code submitted in Figure 4 is definitely working, but with one substantial reservation: if the "Modality Mode" checkbox is selected in the configuration properties (Fig. 10). Otherwise, its use will cause an error.
Fig.10.

In order for this not to happen, it is in the module forms of the reference item form, go to the text menu-\u003e Refactoring-\u003e Recommended Synchronous Calls-\u003e Convert Module Calls.

After some time, synchronous calls will automatically be converted to asynchronous, and the code will take the form (Fig. 11)

Fig.11

Technological platform 1C: Enterprise 8 allows you to save arbitrary files in the information base, get them from there and use different ways. Consider these operations on the examples.

Before downloading the file to the 1C information database, you need to get full address File on disk. Working with file selection dialogs is described in.

Requisite (or register resource) is used to store files. Stranger.

Loading an arbitrary file to 1C information database

Any file can be represented as binary data and download to Strangeries.

When converting binary data into an object Stranger Design used new storage (data, compression) With two parameters:

  1. Data - binary data to be placed in the repository
  2. Compression - Degree of compression algorithm Deflation. An integer in the range -1 ... 9. -1 - Degree of compression by default. 0 - no compression, 9 is the maximum compression ratio. Default value: -1. The option is optional, if not specified, the compression is not used.

// Transform the file to binary data
File \u003d new binary (path);

// Create a new storage facility

Stored \u003d new storage (file, new compressed (9));

Saving an arbitrary file from the 1C information database to the disk

To save the file from the 1C database to the disk, you need to determine the path and file name. To do this, there is a dialog for saving files, working with which is described in.

// Get binary data from the repository
// Storaded - Props of the object with the type of repositse

// write the received data to the disk
// In the variable path is the full address of the file on the disk
Data. Write down (path);

Viewing a file located in the information database 1c

To view the file saved in the database, it is necessary that the application will be installed on the computer that opens this file.

// Get the name of the temporary file with the necessary expansion.
// In the variable extension, you need to put the file extension, for example, "PDF"
Path \u003d OPERATEQUMEN File (expansion);

// Receive data from the repository
// Storaded - Props of the object with the type of repositse
Data \u003d stored. Receive() ;

// write data to a temporary file
Data. Write down (path);

// try to open the file in the application intended for it
// If the application is not found, a system dialog will appear "Open with ..."
Running the application (path);

In the value storage, you can save almost any information, for example,

... pictures (pictures):

Team image. Project \u003d Sprkini.Link; Teamwork .Vidata \u003d listing. Vidual information objects. Image; Storage \u003d new storage (new carotine, new compressed ()); Team process. Everbill \u003d storage. Pour ();

// In this place, it turns out everything ... elementforms. Polekartinki1. Cartink \u003d storage. Pour (); Team processing. To recruit ();

... Tabular document:

TABO \u003d New Timber; Tabdow.Stiver (elementforms. Poletablichnogymenta1); Repository \u003d new storage (tabid); Write down ();

Extrudresses

Procedure RestoreShusting (Element)

Tabdok \u003d Storage. Pour (); If the Tabdow<>It is indefinitely the elementforms. Poletoleschnogymenta1.Shet (TABD); Ended;

Extrudresses

... arbitrary files (binary data):

Xs \u003d new storage (new binary (file));

The eight supports the compression of the data placed in the repository:

Xs \u003d new storage (new binary (file), new compressed (9));

... external processing and reports:

Procedure Switchingprocessing / requisite)

Deterrent \u003d new compressed (9); // 9 maximum requisite \u003d new storage (new binary ("C: \\ reports \\ report.epf", degree));

Extrudresses

Procedure for running processing (requisite)

ImagremnyFile \u003d Catalog Violence Files () + "Report.epf"; Two) \u003d requisittypusto. Pour (); Bicked. To recruit (imagremenphal); External processing \u003d external processing. Create (imaginenefile); External processing. Forecorm (). Open ();

Extrudresses

Work with storage

If these were doubled, they can be restored from the storage of the value method and write to the file to write ().

If typcoon (storage)<> Type ("binary") then

Binary) \u003d storage. Pour ();

Binary) \u003d storage;

Ended; Bichelted. To recruit (name);

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

Running the application (name file);

To clear the type storage field, you need to assign it indefinitely:

Requisite \u003d uncertain;

Working with files and pictures in the embedded language 1C: Enterprises 8

Purpose

In the managed application implemented new mechanism Works with files. It provides file sharing between the information base and the client application. A feature of this mechanism is that it is focused on using thin client and a web client and developed taking into account restrictions on working with files imposed by web browsers.

The mechanism is a set of methods with which you can put the data stored locally from the user to temporary storage information base, transfer this information from the temporary storage to the database and get it back to the user's computer. The most common applied tasks solved by this mechanism is the storage of accompanying information, for example, images of goods related to documents contracts, etc.

Scope methods

Temporary storage

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

The need for a temporary storage arises due to the way in the web browser work model you need to transfer the filed by the user directly to the server without the possibility of storing it on the client. When transferring a file, it is placed in a temporary storage and can already be used when writing an object to the database.

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

The file or binary data placed in the repository is identified by a unique address, which can later be used in recording, read or delete operations. This address is issued methods for recording a temporary storage file. A separate method in the embedded language allows you to determine whether the address transferred to the address indicating the data in the temporary storage.

Information base

The mechanism allows access to binary data stored in details of the type of storage.

As in the case of temporary storage, access to information is possible through a special address. You can get it through a special method, passing the link to the object or the record of the record of information, and the name of the props. In the case of tabular part, it is additionally required to transfer the table part lines index.

Methods for working with files have a limit when working with information base details. For them, unlike temporary storage, only reading information is available, but not its record or delete.

Description of file working methods

Saving data in temporary storage

The most typical scenario of using this mechanism provides for the initial placement of the user data in the temporary storage. For this purpose, two methods are intended: placefile () and placing lodging ().

The first method, placing (), places the file from the local file system in the temporary storage. The method can take the target address in the repository. If it is not defined or is an empty string, it will be created new file. And the method will return its address through the appropriate parameter.

If a parameter that defines the interactive mode of operation is true, the method will display the standard file selection dialog box in which you can select a file for the premises. In this case, the method will also return the address of the selected file.

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

The second method, placing-loving age (), is similar to the previous one, except that it is available on the server, and the data for recording to a temporary storage is not in the form of a path in the file system, and in the form of variable type Two. In the same way, if the target address is not specified, a new file is created in the repository. His address is returned as a result of the function.

Getting a file from temporary storage

When writing an object in the information database, you may need to extract data from the temporary storage and place them, for example, in props. To do this, there is a corresponding server method - getting filthylishery (). This method retrieves data from the temporary storage and returns them as a result. To do this, you must specify the address in the temporary storage. This address returns the above-described parameters () methods and placing anemium () in case of successful execution.

Deleting a temporary storage file

After the data is stored in the details, the file in the temporary storage can be deleted. To do this, there is a delete file method (), which deletes a file from the temporary storage. The method takes the file address in the temporary storage parameter. Available on the server.

Checking addresses to belong to temporary storage

The file address may indicate both the temporary storage and the requisites in the information base. To verify its type, there is a method of magnifier ().

It checks that the transmitted address is an address indicating the repository. Returns truth if the address indicates a temporary storage. The method is available on the server.

Obtaining addresses requisite

After the data is placed in the props in the information base, it may be necessary to access them using file methods.

But before obtaining data, such as the details, it is necessary to obtain the address of this props. For this, there is a method for the receptionress ().

Its purpose is to return the file address in the information database on source parameters. To do this, it is necessary to transfer the object of the object (this can be both a reference to the object and the key of the record of information) and the name of the props. If you need to get the address of the file stored in the details of the tabular part, to the confiscation name in the parameter specifying the name of the props, you must add the name of the tabular part and the point ".". The method is available both on the client and on the server.

Getting a file from the information base

The receive file () method receives a file from the information base and saves it to the local file System User. The first parameter determines the address of the file in the requisition or in the temporary storage of the files. The second parameter determines the target location of the received file. In not interactive mode, you must specify the path. In the interactive mode, the parameter is optional.

By default, the method is executed in interactive mode, that is, the last parameter is equal to the truth. This means that a dialog box is issued in which you can specify the action with the file received: run it or save by the user-specified location. If an interactive mode is active, and the target path parameter to the disk file is not specified, the file open operation is not available. Returns boolean value. A lie means that the user has selected the cancellation of the operation in the File Saving dialog box in the interactive mode.

Example of using file methods

// Receipt in the interactive mode of the file from the disk // and placing it in the temporary storage & Schedule Procedure Select FailsDiski recruit ()

AG selected; To change the addivation agent; If placed (addivatives-grained, selected, truth) then object. IMAFEEL \u003d selected; Plain fairy (addivatives); Ended;

Extrudresses

// Copying the file from the temporary storage to the props // Reference, object entry, deleting a file from temporary // Storage & Nasserver Procedure Place Failed (addivationReenship)

Element Advisor \u003d RequisitformAnd ("Object"); Two-winged \u003d get-fiveylishery (addivatives); Element Advixer. DataFile \u003d New storage (bichered); Filenadadisk \u003d New file (element perm.imyfyle); Element Advice. IMAFILE \u003d FilePutnadisk. Element Advixer. recruit (); Modifying \u003d false; Delete File Remirement Elementary (AddressReensional Entry); Recentlyrerevisitforms (element permanent, "object");

Extrudresses

// Read the file from the props and save it // on local disk In an interactive mode & Customize, read File & Cravenadadisk ()

Address \u003d OPERADLESPHEFILEVINFORMATION Base (object. Link, "Puttails"); Opt file (address, object. Imiafyle, truth);

Extrudresses

Support addresses in the field Pictures

Control field control supports the image display specified by the file address in the temporary storage or in the database.

To do this, in the property of the form element, it is necessary to specify the props of a string type. The value of this props and will be interpreted as a picture address.

Example // Binding fields Pictures to the address of the picture in temporary // Storage. Addaparticles Props String Type Forms

Put File (Addictory, Truth)

Picture. Data \u003d Addaparticles

Restrictions when working with a web client

The work of the described mechanism when using a web client has some limitations. These restrictions are related to the features of the browser security model. For example, the client cannot save the file to the local file system independently, that is, only an interactive version of client methods in place () and receive files () are available. When you try to use not an interactive mode, an exception is generated. Dialog boxesDisplayed in interactive mode specific for a specific type of browser.

Features when working with warehouses on the client

Problem:

When the document in the table part there is a props of the type of storage, it slows down the opening of the document form if the details are recorded in this proper.

Estimated reason:

Perhaps, when opening a form, it is not transferred to the client that the link to the data in the repository data is transmitted, but the data themselves.

Decision

  • In the properties of the table props, there is always the "Use Always" flag. If it is installed, the field content is always transmitted between the server and the client - for example, when opening the form. This flag must be disabled, but it is necessary to take into account this in the code, since the default values \u200b\u200bof this field will not be on the client. An example can be found in 1C: Archive.

Even better to use temporary storage To transfer files between the client and the server.