Display DB blob type in Flex - apache-flex

My Mysql database stores images (in PNG, JPG)of our personnel and it's field type is set to longblob.
Is there any possibility to load blob data type using HttpService and render it in Image component in Flex .??? ^..^
I'm eager to know about as it comes in handy in the nearest future!!!

You can, but I don't see the point of storing your images in a DB.
Simplest way to get it into an Image is to load the blob, convert to a ByteArray which you can set as the source of of said Image.

If you override HttpService you can use it to receive binary data. If you don't want to override HttpService you have the option of encoding you binary data in base64 before sending it.
But if have the option to store the images in a directory on the server and just send links to the client - that would be a better solution.

Related

How do get the path of destination where image is saved using Glide (Image loading library Android)

Glide uses disk caching (both internal and external). The way it stores the file name is encoded in some format. It is possible to get the original file name/file path, where the image is downloaded ?
Glide uses a two-level cache in 3.x: SOURCE and RESULT. The default caching (if you don't specify a .diskCacheStrategy() is RESULT. Currently there's no public way to figure out which file corresponds to a normal Glide load (RESULT cache).
The main article about caching is: https://github.com/bumptech/glide/wiki/Caching-and-Cache-Invalidation
Many have tried to mess with the cache.
The solution is based on your use case and you can choose one of:
.sigunature(): invalidate a single item in cache when signature changes
.downloadOnly(): get the File handle to a SOURCE cache item
.asBytes(): returns JPG/PNG encoded byte[] instead of a Drawable/Bitmap
Glide.get(context).clearDiskCache(): last resort only, removes everything

Does morphia support GridFS?

Is there a implementation of GridFS in Morphia? How is this?
I am using a webservice and receive base64 input, which is transform in a bit array, such like this:
private bit [] image;
I created my model class to communicate with morphia, however, each document of that collection will have a lot of images, is something like an event has a lot of editions and an edition has its images.
How can I mapped that attribute in morphia?
GridFS is not yet supported by Morphia, if you want to store information into GridFS from your application you need to use the native Java GridFS API ( see https://github.com/mongodb/mongo-java-driver/blob/master/src/test/com/mongodb/gridfs/GridFSTest.java )
To answer your question
How can I mapped that attribute in morphia?
The code you have written will work, and your images will be saved as bytes into the document, in the attribute "image" like any other attribute. As you probably know MongoDB & Morphia are using BSON in memor, on the network and in the database, this means it will save the bytes as they are sent.
So of you still want to store the image in the document, not an issue at all if they are small, you just have to be careful about the overall size of the document. As you probably know a document cannot exceed 16Mb.

File extension for 'application/ole' attachment

Email messages in RTF format can have embedded in-line attachment. MAPI gives file name of inline attachment but without extension. How to know the extension?
MAPI gives content-description as 'Picture (Device Independent Bitmap)'. I can depend on this data to compute file extension as BMP. But this works for BMP but not for PDF, WORD, EXEL. I would like to know if there is a solution (like looking in to REGISTRY) that works for everything without me changing the code for every file type.
Mime headers generated by reading MAPI properties of attachment. You see that attachment is missing extension.
Content-Disposition: inline; filename=ATT87266
Content-Transfer-Encoding: Base64
content-type: application/ole;name="Picture (Device Independent Bitmap)"
content-description: Picture (Device Independent Bitmap)
Embedded OLE attachments are not files, they are IStorage COM storage. If you look at an OLE attachment with OutlookSpy (I am its author - click IMessage button, go to the GetAttachmentTable, double click on the attachment), you will see that there is no PR_ATTACH_DATA_BIN binary property where the regular by-value attachments are stored; what you have instead is PR_ATTACH_DATA_OBJ object (PT_OBJECT) property. You can open it in OutlookSpy by right clicking and selecting IMAPIProp::OpenProperty, then selecting IStorage as the interface.
The OLE storage will contain several streams that contain flags used by Outlook, metafile used to render the object when viewing it, and the actual data used by whatever OLE server was used to create the OLE attachment. You can look at the storage CLSID to figure out the application used to create the attachment. Once you know that, you can extract the raw file data from the application-specific storage stream inside that IStorage.

File upload and read from database

I am using file upload mechanism to upload file for an employee and converting it into byte[] and passing it to varBinary(Max) to store into database.
Now I what I have to do is, if any file is already uploaded for employee, simply read it from table and show file name. I have only one column to store a file and which is of type VarBinary.
Is it possible to get all file information from VarBinary field?
Any other way around, please let me know.
If you're not storing the filename, you can't retrieve it.
(Unless the file itself contains its filename in which case you'd need to parse the blob's contents.)
If the name of the file (and any other data about the file that's not part of the file's byte data) needs to be used later, then you need to save that data as well. I'd recommend adding a column for the file name, perhaps one for its type (mime type or something like that for properly sending it back to the client's browser, etc.) and maybe even one for size so you don't have to calculate that on the fly for each file (useful when displaying a grid of files and not wanting to touch the large blob field in the query that populates the grid).
Try to stay away from using the file name for system-internal identity purposes. It's fine for allowing the users to search for a file by name, select it, etc. But when actually making the request to the server to display the file it's better to use a simple integer primary key from the table to actually identify it. (On a side note, it's probably a good idea to put a unique constraint on the file name column.)
If you also need help displaying the file to the user, you'll probably want to take the approach that's tried and true for displaying images from a database. Basically it involves having a resource (generally an .aspx page, but could just as well be an HttpHandler instead) which accepts the file ID as a query string parameter and outputs the file.
This resource would have no UI (remove everything from the .aspx except the Page directive) and would manually manipulate the response headers (this is where you'd set the content type from the file's type), write the byte stream to the client, and end the response. From the client's perspective, something like ~/MyContent/MyFile.aspx?fileID=123 would be the file. (You can suggest a file name to the browser for saving purposes in the response headers, which you'd probably want to do with the file's stored name.)
There's no shortage of quick tutorials (some several years old, it's been around for a while) on how to do this with images. Just remember that there's essentially no difference from the server's perspective if it's an image or any other kind of file. All the server needs to do is send the type in the response headers and write the file's bytes to the client. How the client handles the file is up to the browser. In the vast majority of cases, the browser will know what to do (display an image, display via a plugin a PDF, save a .doc, etc.).

Getting image height and width when image is saved in database

I save my images into my SQL Server Database with ASP.NET(2.0).
(imageData -> image) (imageType -> varchar) (imageLength -> bigint)
Thus the imageData will be "Binary data" and the imageType will be like "image/gif" and the imageLength will be like "6458".......
Is it possible to get the image HEIGHT and WIDTH from my VB.NET code inside my ASP.NET?
I want to make my picture box on my web form the size of the actual image that is saved in my database.
Regards
Etienne
Assuming you have the data in a stream:
System.Drawing.Image.FromStream(yourStream).Height
You are probally better doing this when you save the image to the DB, as I'm sure that loading the image object isn't going to be cheap.
Edit
If we take this to email then the next guy with this issue won't have a record of our solution. Let's keep it in the forum for now.
Just so we know, I am a C# developer so I'm not going to try and remember vb.net syntax if this is an issue and you need help converting let me know.
You have an IDataReader I'm assuming which is pulling an Image or binary varbinary etc field from your DB. You need to load it into an object which derives from System.IO.Stream. For our purposes a MemoryStream is the perfect choice as it doesn't require a backing store such as a disk.
System.IO.MemoryStream yourStream = new System.IO.MemoryStream(dr["imgLength"] as byte[]);
System.Drawing.Image yourImage=System.Drawing.Image.FromStream(yourStream);
yourImage.Height;
yourImage.width
I would save the height and width of the image in separate columns when you save the image to the database intially. Then when you do your select statement to read the image out of the database, you can also access the height and width fields from the database.
Alternatively you can access the height and width information when you load the image out of the database and then set the height and width properties before assigning the image to the picture box.
You can get the height and width but you are going to have to load the whole image into memory using the system.drawing.image library, each time you need that info.
Better to save it as separate fields the first time you save it to the database, that is generally what I do.
Sounds like you want 2 more fields in your database, height and width.
I strongly believe that after a few hundred gigabytes of images you'll find yourself thinking that the file system and static file http servers are better suited than the databas for storing images. It also allows you to use thousands of existing free tools to work with, move, host, etc the images. Your database might get busy, and it's not easy to cluster.
Dim mobj_wc As New System.Net.WebClient
Dim obj_BookOriginalImage As System.Drawing.Bitmap
Dim ImageInBytes() As Byte = mobj_wc.DownloadData(mstr_BookURL & mds_BookDetails.Tables(0).Rows(0).Item("BookImage"))
'CREATE A MEMORY STREAM USING THE BYTES
Dim ImageStream As New IO.MemoryStream(ImageInBytes)
obj_BookOriginalImage = New System.Drawing.Bitmap(ImageStream)
mint_ImageWidth = obj_BookOriginalImage.Width

Resources