Solved! Go to Solution.
import arcpy, os from arcpy import da inTable = "C:\\Connection to RCES_P.sde\\SIS_ADM.IMAGES" # table with identifier (SITE_CODE), imageID number (IMAGE_ID), and photo in BLOB field (PHOTO) savepath = "\\\\mcflight01\\WebImages" # initial path to save images/sub folders with da.SearchCursor(inTable,['SITE_CODE','IMAGE_ID','PHOTO']) as cursor: for row in cursor: SITE_CODE = str(row[0]) # gets feature identifier from table (SITE_CODE) as string Fid = str(int(row[1])) # gets ImageID from table (IMAGE_ID) as string without decimal point binaryRep = row[2] # get photo from BLOB field as binaryRep variable filename = (SITE_CODE.replace(':','_')).replace('/','') + "_" + Fid + ".jpg" # appends site_code to filename replacing : and /'s folder = savepath + os.sep + SITE_CODE.replace(':','_') # appends site_code to folder replacing : with _ if binaryRep: if not os.path.exists(folder): os.system("mkdir " + '"' + folder + '"') # if doesn't already exist, make folder using folder variable open(folder + os.sep + filename, 'wb').write(binaryRep.tobytes()) # this actually saves the BLOB stored in binaryRep to filename variable del binaryRep del row
I have a mobile project running using ArcGIS mobile for Windows...pictures
cd C:\Python27\ArcGIS10.1 Python C:\arcgisserver\python\finish.py pause Exit
Dustin,
I have a similar workflow, with photos stored in BLOB fields and one to potentially many photos per feature. The attachemnts feature doesn't really support 1:many so I have a python script that extracts the jpeg photos from the blob and saves them in a folder. As it is writing the blobs, I capture the path and filename that I am saving them to (as well as my feature ID) and append to a list, then at the end of my script, I insertCursor the list to populate a FGDB table. Now I not only have the jpeg stored local in a folder, I also have a ready-made table with all my paths ready to join/calculate to the feature class data that can be used for my link field.
Of course, I had to make a virtual directory on the server pointing to the folder I saved all my jpegs in, then had to go into IIS and, for that virtual folder, allow directory browsing as I often have many photos per site (if just one photo, my "path" actually points to the jpeg file, if more than one, it points to the folder.
This was kind of cluttery, especially for the sites with multiple photos, as IE doesn't give thumbnail views, so, all you see is a list of the somewhat cryptic filenames, and need to click on each photo to view it.
So, I took it one step farther. After my python script extracts and saves the jpegs from the BOLBs, writes the "lookup table", joins/calculates the URL info to my feature class, it then runs a slightly modified version of pyGallery. This creates a gallery for my photos similar to ( http://pygallery.sourceforge.net/samples/ ). So now, if there is one photo, my popup says "Click for Photo", and it takes you direclty to the image viewed in a browser. If there are more than one image, it says "Click for Photos", and if you click, it will take you to the index/thumbnail gallery page for that feature, with all the photos.
So far, not only the best way I've came up with for BLOBs, but also for one:many photos in Flex.
In case this gives you some ideas,
R_
import arcpy, os from arcpy import da inTable = "C:\\Connection to RCES_P.sde\\SIS_ADM.IMAGES" # table with identifier (SITE_CODE), imageID number (IMAGE_ID), and photo in BLOB field (PHOTO) savepath = "\\\\mcflight01\\WebImages" # initial path to save images/sub folders with da.SearchCursor(inTable,['SITE_CODE','IMAGE_ID','PHOTO']) as cursor: for row in cursor: SITE_CODE = str(row[0]) # gets feature identifier from table (SITE_CODE) as string Fid = str(int(row[1])) # gets ImageID from table (IMAGE_ID) as string without decimal point binaryRep = row[2] # get photo from BLOB field as binaryRep variable filename = (SITE_CODE.replace(':','_')).replace('/','') + "_" + Fid + ".jpg" # appends site_code to filename replacing : and /'s folder = savepath + os.sep + SITE_CODE.replace(':','_') # appends site_code to folder replacing : with _ if binaryRep: if not os.path.exists(folder): os.system("mkdir " + '"' + folder + '"') # if doesn't already exist, make folder using folder variable open(folder + os.sep + filename, 'wb').write(binaryRep.tobytes()) # this actually saves the BLOB stored in binaryRep to filename variable del binaryRep del row