# Works arcpy.AddAttachments_management("C:/test/test.sde/test.sde.test_table","objectid","C:/test/test.csv","FileID","FilePath","#") # Cleanup arcpy.RemoveAttachments_management("C:/test/test.sde/test.sde.test_table","objectid","C:/test/test.csv","FileID","#") # Register the table as versioned: arcpy.RegisterAsVersioned_management("C:/test/test.sde/test.sde.test_table") # Produces this error: http://resources.arcgis.com/en/help/main/10.1/00vp/00vp0000002n001180.htm arcpy.AddAttachments_management("C:/test/test.sde/test.sde.test_table","objectid","C:/test/test.csv","FileID","FilePath","#") # Unregister the table as versioned: arcpy.UnregisterAsVersioned_management("C:/test/test.sde/test.sde.test_table") # Still produces this error: http://resources.arcgis.com/en/help/main/10.1/00vp/00vp0000002n001180.htm arcpy.AddAttachments_management("C:/test/test.sde/test.sde.test_table","objectid","C:/test/test.csv","FileID","FilePath","#") # Oops, looks like the __ATTACH table is still versioned (gets registered automatically, but not unregistered) # Note: if I only unregister the __ATTACH table, then the table it is associated with does get automatically unversioned. arcpy.UnregisterAsVersioned_management("C:/test/test.sde/test.sde.test_table__ATTACH") # Now this works again: arcpy.AddAttachments_management("C:/test/test.sde/test.sde.test_table","objectid","C:/test/test.csv","FileID","FilePath","#")
edit = arcpy.da.Editor("C:/test/test.sde") edit.startEditing(False, True) edit.startOperation() cur = arcpy.da.InsertCursor("C:/test/test.sde/test.sde.test_table__ATTACH",["rel_objectid","content_type","att_name","data_size","data"]) file = memoryview(open("C:/test/test.pdf","rb").read()) row = [801,"application/pdf","test.pdf",len(file.tobytes()),file] cur.insertRow(row) edit.stopOperation() edit.stopEditing(True)
Solved! Go to Solution.