arcgis-python-api icon indicating copy to clipboard operation
arcgis-python-api copied to clipboard

Problem uploading file using absolute path (with workaround and code fix)

Open eykamp opened this issue 6 years ago • 0 comments
trafficstars

I found a bug in gis.content.add(). The particular code:

if not os.path.isfile(os.path.abspath(data)): 
    raise RuntimeError("File("+data+") not found.")

   What's happening here is the code is preparing to upload a file, and wants to make sure it exists before proceeding.  That's great when it works.

The data var contains the path to the file to be uploaded.  Unfortunately, abspath prepends the current working folder, which is often the folder where the local environment is based.  This prepending only occurs when checking the existence of the file, and fails if you provide an absolute path to your data.  The fix would be to add "and not os.path.isfile(data)" to the end of the if statement.  

I do have a workaround, which is to replace the drive letter with "..\..\..\..\..\..\..\..\..\..\..\..\..\..\" in data, which fools abspath into recognizing that the file exists.  This workaround is pretty lame, and should be fixed.

eykamp avatar Aug 01 '19 17:08 eykamp