How to store a file in the database?

Understanding basics of 1C:Enterprise platform. To start working with 1C:Enterprise platform visit Getting started page

#1
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Sep 27, 2011
Company:

How to store a file in the database? I want attach photos to items.

 
#2
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Mar 15, 2012
Company: no

You should create catalog and attribute in it with type ValueStorage.

 
#3
People who like this:0Yes/0No
Active user
Rating: 5
Joined: Sep 27, 2011
Company:

OK, I've did so but I can not place attribute of this type on a form. It is written in Type column: Not available in form data...

 
#4
People who like this:0Yes/0No
Timofey Bugaevsky
Guest

Joined:
Company:

First you need to use PutFile function to send a file from client to server and pass a string with storage address to GetFile function at server to retrieve it from temp storage.
Next you need to pack it into ValueStorage type attribute and write a container object.

Code
&AtClient
Procedure LoadFile(Command)
   StorageName = "";
   FileName = Object.FileName;
   PutFile(StorageName, FileName, FileName, True, UUID);
   LoadFileServer(StorageName);
EndProcedure


&AtServer
Procedure LoadFileServer(StorageName)
   ObjectValue = FormDataToValue(Object, Type("CatalogObject.StoredFiles"));
   ObjectValue.Data = New ValueStorage(GetFromTempStorage(StorageName));
   ObjectValue.Write();
   ValueToFormData(ObjectValue, Object);
EndProcedure

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.