/tmp
directory/tmp
directory. You have of available space in/tmp
to save any file./tmp
across workflow runs/tmp
directory is stored on the virtual machine that runs your workflow. We call this the execution environment (“EE”). More than one EE may be created to handle high-volume workflows. And EEs can be destroyed at any time (for example, after about 10 minutes of receiving no events). This means that you should not expect to have access to files across executions. At the same time, filesmay remain, so you should clean them up to make sure that doesn’t affect your workflow.Usethetempfile
module to cleanup files after use, ordelete the files manually./tmp
import requestsdef handler(pd:"pipedream"): # Download the Python logo r= requests.get("https://www.python.org/static/img/python-logo@2x.png") # Create a new file python-logo.png in the /tmp/data directory with open("/tmp/python-logo.png","wb")as f: # Save the content of the HTTP response into the file f.write(r.content)
/tmp/python-logo.png
holds the official Python logo./tmp
/tmp
directory. Let’s open thepython-logo.png
file.import osdef handler(pd:"pipedream"): with open("/tmp/python-logo.png")as f: # Store the contents of the file into a variable file_data= f.read()
/tmp
/tmp
you can list them and print the results to theLogs section ofResults:import osdef handler(pd:"pipedream"): # Prints the files in the tmp directory print(os.listdir("/tmp"))
import osdef handler(pd:"pipedream"): print(os.unlink("/tmp/your-file"))
/tmp
/tmp
./tmp
/tmp
in an HTTP request.multipart/form-data
requestimport requestsfrom requests_toolbelt.multipart.encoderimport MultipartEncoderimport osdef handler(pd:"pipedream"): download_url= "https://example.com" upload_url= "http://httpbin.org/post" file_path= "/tmp/index.html" content_type= "text/html" # DOWNLOAD with requests.get(download_url,stream=True)as response: response.raise_for_status() with open(file_path,"wb")as file: for chunkin response.iter_content(chunk_size=8192): file.write(chunk) # UPLOAD multipart_data= MultipartEncoder(fields={ 'file': (os.path.basename(file_path),open(file_path,'rb'), content_type) }) response= requests.post( upload_url, data=multipart_data, headers={'Content-Type': multipart_data.content_type} )
/tmp
limitations/tmp
directory can store up to of storage. Also the storage may be wiped or may not exist between workflow executions.To avoid errors, assume that the/tmp
directory is empty between workflow runs. Please refer to thedisk limits for details.Was this page helpful?