upload zipfile to managed folder from dataikuapi

ckilduff16
ckilduff16 Registered Posts: 7 ✭✭✭
edited July 16 in Using Dataiku

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

Tagged:

Best Answer

  • Zach
    Zach Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 153 Dataiker
    edited July 17 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

Setup Info
    Tags
      Help me…