upload zipfile to managed folder from dataikuapi
Hi,
I have a local directory with a bunch of zip files in it which I would like to move to a managed folder in dataiku. I would then like to automate the upload of new files monthly. I dont have access to the dataiku server file system other than going through the dataikuapi or through the dataiku website. I have tried the below code and keep getting errors. Please let me know if this is possible, Thank you!
-Cameron
import dataikuapi # Set Dataiku URL and API Key host = "myhost" apiKey = "mykey" file = 'absolute path to my zip file' filename = 'what I want file to be named in managed folder' # Create API client client = dataikuapi.DSSClient(host, apiKey) # Ignore SSL checks as these may fail without access to root CA certs client._session.verify = False # Get a handle to the Dataiku project, must use Project Key, take it from Project Home URL, must be all in uppercase project = client.get_project("project name") # Get a handle to the managed folder you want to upload a file to, must use Folder ID, take it from URL when browsing the folder in Dataiku. Case sensitive! managedfolder = project.get_managed_folder("folder name") # Upload a local file to the managed folder with zipfile.ZipFile(file, "r") as f: #Tried the below commented out code but got f.read() error #managedfolder.put_file(filename, f) #After trying the above code I tried the below line and got a type error managedfolder.upload_folder(filename, f)
Operating system used: windows
Best Answer
-
Hi @ckilduff16
,It sounds like you just want to upload the zip files to a managed folder as is, without extracting them, correct? In that case, you don't need to use zipfile.ZipFile.
You can upload a single file using put_file:
with open(file, "rb") as f: managedfolder.put_file(filename, f)
Alternatively, you can upload an entire directory at once using upload_folder:
managedfolder.upload_folder("zip-dir", "/local/path/to/zip-dir")
Thanks,
Zach
Answers
-
What if I have a similar problem, except I do want to extract the contents of the zip file into the managed folder?
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,112 Neuron
Hi Cate, welcome to the forums. This is a solved thread. Please post a new thread with your new question.