Hello for all,
I have a Standalone Table with Binary Large Object (BLOB) field. Into BLOB field of the Table are various documents (Image, Excel Document PDF Document and so on).
I need to programmatically get this document and work it using Row Cursor.
How can I get the MemoryStream from the Row object?
Thank you in advance,
Laurentiu
Hi Laurentiu,
Values of BLOB fields are returned as COM objects now, so it seems that support of BLOBs editing is not implemented in current version (1.4) of the ArcGIS Pro SDK. I hope ESRI team working on ArcGIS Pro SDK will pay attention to this bug.
Max
Hi Laurentiu,
As Max suggested, we don't have support for reading and editing BLOB fields yet. It has been scheduled for the next release.
As a workaround, could attachments be used to store binary data? We have support to store binary data by assigning MemoryStreams or obtaining MemoryStreams from the Attachement table. Please refer to How to create a memory stream and Adding Attachments for more information.
-Sree
Hi Sreevatsa,
Do you have information about supporting reading and writing BLOB fields in ArcGIS Pro 2.3?
You can now do this with either the Inspector class within an EditOperation:
//Run on MCT
QueuedTask.Run(() =>
{
//get selected feature into inspector
var selectedFeatures = MapView.Active.Map.GetSelection();
var insp = new Inspector();
insp.Load(selectedFeatures.Keys.First(), selectedFeatures.Values.First());
//read file into memory stream
var msr = new MemoryStream();
using (FileStream file = new FileStream(@"d:\me\images\Hydrant.jpg", FileMode.Open, FileAccess.Read))
{
file.CopyTo(msr);
}
//put the memory stream in the blob field
var op = new EditOperation();
op.Name = "Blob Inspector";
insp["Image"] = msr;
//insp.ApplyAsync();
op.Modify(insp);
op.Execute();
//read blob field and save to a file
//assume inspector has been loaded with a feature
var msw = new MemoryStream();
msw = insp["Image"] as MemoryStream;
using (FileStream file = new FileStream(@"d:\temp\blob.jpg", FileMode.Create, FileAccess.Write))
{
msw.WriteTo(file);
}
});
or with the row object in a rowcursor:
QueuedTask.Run(() =>
{
var editOp = new EditOperation();
editOp.Name = "Blob Cursor";
var featLayer1 = MapView.Active.Map.FindLayers("Hydrant").First() as FeatureLayer;
editOp.Callback((context) => {
using (var rc = featLayer1.GetTable().Search(null, false))
{
while (rc.MoveNext())
{
//context.Invalidate(rc.Current);
//read file into memory stream
var msr = new MemoryStream();
using (FileStream file = new FileStream(@"d:\me\images\Hydrant.jpg", FileMode.Open, FileAccess.Read))
{
file.CopyTo(msr);
}
rc.Current["Image"] = msr;
rc.Current.Store();
//read the blob field to a file
var msw = new MemoryStream();
msw = rc.Current["Image"] as MemoryStream;
using (FileStream file = new FileStream(@"d:\temp\blob.jpg", FileMode.Create, FileAccess.Write))
{
msw.WriteTo(file);
}
//context.Invalidate(rc.Current);
}
}
}, featLayer1.GetTable()); //Pass as parameters the datasets
editOp.Execute();
});
Thank you Sean.
I would be nice to see that information in Snippets and API reference
Hi Sean,
One more question. Is it possible to read/write from/to Raster type field? If yes- how?
I'll get that snippet in for blobs.
The raster field isn't supported in the same way currently. Its on the list.