![]() | |||||||||||
| |||||||||||
Downloading a file from an S3 bucket Description Demonstrates downloading an object from an S3 bucket to a local file.
Source Files By clicking on a file name, a preview is opened at the bottom of this page.
download.mos (!******************************************************* * Mosel S3 Integration Examples * * ============================= * * * * file download.mos * * ````````````````` * * Example of downloading a file from an S3 bucket. * * * * You can use the example 'upload.mos' to create the * * remote object that is downloaded by this example. * * * * Note: this must either be run on a cloud component * * (e.g. Xpress Workbench on DMP), or the user must * * enter their own S3 bucket URL and access * * credentials where indicated below. * * * * (c) 2017 Fair Isaac Corporation * * author: James Farmer, 2017 * *******************************************************!) model S3DownloadExample uses "s3" parameters ! Set to 'true' when running this model within DMP, ! 'false' when on-premise ON_CLOUD=true ! On-premise, user must specify their own S3 credentials ! Fill in yours in the lines below S3_BUCKET_URL = '' S3_REGION = '' S3_ACCESS_KEY_ID = '' S3_SECRET_KEY = '' S3_SESSION_TOKEN = '' ! Optional end-parameters declarations LOCAL_FILE="MyDownloadedFile.txt" OBJECT_KEY="MyFile.txt" mybucket: s3bucket end-declarations if ON_CLOUD then ! On the cloud, use the DMP 'solutiondata' bucket s3init( mybucket, S3_DMP_SOLUTIONDATA ) if s3status(mybucket)<>S3_OK then writeln("Error initializing S3 folder: ", s3getlasterror(mybucket)) exit(1) end-if else ! On-premise, user must specify their own S3 credentials ! Fill in yours in the lines below mybucket.url := S3_BUCKET_URL mybucket.region := S3_REGION mybucket.accesskeyid := S3_ACCESS_KEY_ID mybucket.secretkey := S3_SECRET_KEY mybucket.sessiontoken := S3_SESSION_TOKEN end-if ! Download remote object to local file writeln( "Downloading from ",OBJECT_KEY," to local file ",LOCAL_FILE ) s3getobject( mybucket, OBJECT_KEY, LOCAL_FILE ) ! Check for errors if s3status(mybucket)<>S3_OK then writeln("Error returned by S3 service: ", s3getlasterror(mybucket)) exit(1) end-if writeln( "Downloaded ok" ) end-model
| |||||||||||
© Copyright 2024 Fair Isaac Corporation. |