The Blob data type allows you to store images, spreadsheets, videos, audio files, and any other type of documents in the database, taking advantage of the different integrity and control mechanisms provided by the DMBS. There is a way to save blob fields automatically in the database using a web interface (web transaction). There is also an easy way to display a blob field in the web form: a File Upload User control control is generated, and, optionally, an embedded window in which the content (image, video, etc) is shown. Note: Using BlobFile data type instead of Blob data type, the data can be stored using any external storage Summary:
Display advantagesA blob in the web form can be visualized automatically as an image, video, audio, document, etc, depending on the content of the blob field. It can be displayed as a link, to allow the user to click on it and display the blob, or it can be shown embedded in the web form. Maintenance advantagesTo insert or update blob fields in the database, a file selection dialog appears, which enables the end user to browse the file system structure of the client PC (where the Internet browser is running). The process of uploading the file is then automatic. The user chooses a file that will be uploaded to the server and saved in the database. And in runtime you will see: The file selected is uploaded temporarily to a directory in the web server, and then, on the next POST (when the user confirms the transaction) it is saved in the database. When the blob stores heterogeneous types of filesIn some cases, it is necessary to work with different types of files, for example, the same database field contains Word documents, photographs in JPG and GIF format, and video files. As a result, in some cases, it may be necessary to capture and save the extension of the files while uploading them, so this knowledge is available when you download the same files. Having the file extension helps in many cases in which the Internet navigator need to know the file format in order to display it, or in cases in which the WebServer prohibits uploading files without extension. There is a way of automatically capturing the Name and Extension of the file that is being uploaded. This information will also be used when the file is downloaded. The main goal is to be able to run the application in servers that have a maximum level of security and don't allow uploading files without extension. In sum, you have two alternatives if you want to keep heterogeneous files in the same field of the table (docs, jpgs, xmls, etc):
Let's look at the attribute properties: File Type Attribute PropertyIt is available only for blob type attributes. The possible values for this property are any char or varchar attribute of the same table which the blob attribute belongs to. This property identifies an attribute that holds the extension of a Blob data type attribute. A Blob data type attribute may store files. Those files may all be the same type of files (i.e. Word documents, pictures in a specified format, etc.) or they may be heterogeneous. When working with heterogeneous files you should store the "file type" (extension) in a different attribute (because the extension isn't stored with the blob itself). In other words, the Blob data type attribute stores the file content and the File Type Attribute stores the file type (or extension). Every time the Blob data type attribute is assigned (either in the user interface or by an assignment command) the value of the FileTypeAttribute is also automatically assigned. That is to say that the FileTypeAttribute is assigned when you upload a blob from a Web Interface (a Web Transaction), a procedure or a Business Component in a batch mode (from a procedure). The default value is (none), stating that no attribute holds the file type. Constraints on the FileTypeAttribute:
Note: If the FileTypeAttribute property is assigned with a value, the corresponding attribute assigned to this property cannot be explicitly modified through a web transaction. File Type Runtime propertyAs we've already explained the FileType property, let's now look at the FileType runtime property. You can use it to retrieve the file extension of a blob, or change it dinamically by using the following sintax: For instance, if you have the following rule in a web transaction: When the file is being downloaded, the FileType is obtained from: File Name Attribute PropertyThe FileNameAttribute property identifies an attribute that holds the File Name of a Blob data type attribute. A Blob data type attribute can store files. The attribute stores the file content but not it's original name. You should set this property if you want to keep track of the original file name. The default value is (none), stating that the original file name is lost.
Note: When downloading the file, it is temporary saved with its original name (which is taken from the FileNameAttribute), plus a random number. So that each file is given a different name, in order to be able to run the application in multiuser and concurrent environments. Managing different Content TypesContent Types are a means of identifying web pages, images, and multimedia files on the Web and in email messages. They allow web browsers and email clients to display content in a correct and safe way. In the case of blobs, it may be necessary to set their Content Type, especially for certain kind of files, or for certain Internet navigators. Commonly used content types include text/html, image/jpeg, model/vrml, video/quicktime, etc. There are two ways to do this in GeneXus: ContentType property (design and runtime control property) ContentType PropertyIt indicates the content type that should be associated with the Blob. For example, the content type of .wav documents is generally audio/wav, for an .xml file it's text/xml, etc. Retrieving the name of the fileYou can query the name of the file by using the FileName property (runtime property). This is a ReadOnly property, which allows you to know the name of the file associated to a blob. When uploading the file, it returns the name of the file which is being uploaded. For instance, if you have the following rule in a web transaction: msg('The uploaded file is ' + Attblob.FileName + '.' + Attblob.FileType) if not Attblob.isempty() on aftervalidate; When uploading the file, Attblob.FileName returns the actual file name. On the contrary, when downloading a file (if it is in a webpanel, for instance), the value returned by the property is based on the value stored in the FileNameAttribute exclusively. This is because the blob by itself doesn't store any information other than the binary file. It doesn't store the extension or the name of the file. Display control propertiesWidth / HeightDetermines the width / height of the blob control in the form. DisplayIt indicates the way the blob content is going to be displayed in the form. It's available in design model and at runtime. The possible values are: Note:If you define a different value than 0 or 1 (only in runtime) in the property, the blob will not be displayed either Inline or Link. LinkTargetWhen the display property is set to "Link", by this property you can choose to show the blob content in a separate window. ParametersWhen the display property is set to "Inline", and the blob content can't be managed by the Internet browser without providing additional information to it, the Parameters property has to be used to provide the necessary information to the browser. (This example runs in Windows Media Player) Note: The Internet browsers need to know which application to use to display certain type of files. That is what the ContentType property is for. For example, in the case of IE, when the content is .mpg, the ContentType should not be video/mpg (as it would be by default), but application/x-mplayer2. In these special cases, the ContentType refers to the application which should show the content instead of the real content type of the file. Environment PropertiesBlob Local Storage PathThis environment property is used to set the web server path where files are temporarily saved when retrieved from the database. That is to say, when you Get data, a temporary file is saved in the Blob Local Storage Path. The extension of the saved file depends on the value of the Blob property called File Type. The Blob Local Storage Path must be accessible from the virtual directory (ie, if the virtual directory is C:\resin-2.0.2\webapps\test an acceptable value for the property would be: C:\resin-2.0.2\webapps\test\resources\rtrepository). Temporary Media DirectoryThis environment property is used to set the web server path where files are temporarily saved when loaded in the database. That is to say, when a Blob is added or updated, it is temporarily saved in this directory. The Temporary Media Directory must be accessible from the virtual directory. ExampleLet's see an example in which we use the Blob data type. We create a Country transaction, with attributes CountryId, CountryName, CountryFlag, and CountryAnthem. The latter two are of the blob type, so that we can store the flag of the country, and its national anthem. We now go to the properties of the blob-type attributes, and in the File Type property, we set png for CountryFlag, and wav for CountryAnthem: Finally, we press F5, and in the Country transaction we insert the country Uruguay, along with its flag and national anthem: FunctionsPathToURL functionAppendixI. In general, Internet Explorer doesn't respect the Content Type returned by web servers and uses a variety of strategies to automatically detect the content type of files.
Note When the blob's content is restricted to images, video or audio, the use of Image, Video or Audio data types should be considered instead the blob data type.
Scope
See also |
Has recibido este mensaje porque estás suscrito al grupo "GeneXus" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a genexus+unsubscribe@googlegroups.com.
Para acceder a más opciones, visita https://groups.google.com/d/optout.
0 Response to "Images BLOB, GeneXus"
Publicar un comentario