Upload files to Aspera that comes with IBM Cloud Object Storage (ICOS) using SDK (Python version)

How to upload a file to IBM Cloud Object Storage (ICOS). This time, we will operate Aspera that comes with ICOS using the Python version of the SDK.

Environment used

3 series is fine, but currently the SDK only supports up to 3.6, so I checked with 2 series.

Setting up the Python SDK

Please set up referring to here. GitHub:IBM-Cloud/data-lake/upload/cos-upload

After setting up pip, run install.sh, For the Windows version, I copied the contents of the file directly and ran the command.

install.sh


pip install --upgrade pip
pip install --upgrade setuptools
pip install "requests>=2.22.0,<2.23.0" "ibm-cos-sdk>=2.5.4" "cos-aspera>=0.1.163682"

IQOS information confirmation

Log in to the IBM Cloud console (web) to verify your ICOS service credentials. The service credentials can be found in the bucket credentials created in ICOS. service_info.png

Run

The command example is as follows.

cos-upload.py <endpoint> <apikey> <bucket_name> <prefix> <file>

Run on Mac

$ python cos-upload.py s3.jp-tok.cloud-object-storage.appdomain.cloud "api-key" test-bucket "" test-upload-python-mac.txt

Initialize COS and Aspera Transfer Manager using endpoint: https://s3.jp-tok.cloud-object-storage.appdomain.cloud

Upload file to COS: /tmp/test-upload-python-mac.txt => test-upload-python-mac.txt
Upload file to COS completed.

Run on Windows

C:\tmp>py -2 D:\Workspace\cos-upload.py s3.jp-tok.cloud-object-storage.appdomain.cloud "api-key" test-bucket "" test-upload-python-win.txt

Initialize COS and Aspera Transfer Manager using endpoint: https://s3.jp-tok.cloud-object-storage.appdomain.cloud

Upload file to COS: C:\tmp\test-upload-python-win.txt => test-upload-python-win.txt
Upload file to COS completed.

Arrival confirmation

Confirm that the upload was successful with the ibmcloud command.

//Confirm that it was uploaded successfully
$ ibmcloud cos list-objects --bucket test-bucket
OK
Found 3 There are objects in the bucket'test-bucket':

Name Last modified date and time Object size
test.txt    Feb 28, 2020 at 02:27:12   14 B
test-upload-python-mac.txt   Mar 05, 2020 at 20:05:11   20 B
test-upload-python-win.txt   Mar 05, 2020 at 21:21:50   20 B

Afterword

I think the points of the Python version are "construction of execution environment" and "understanding the concept of parameter specification at runtime".

I was running on 3.7 series without noticing Require for a while, so I was having trouble with install.sh, but when I implemented it on 2.7 series, it was solved brilliantly, so I lost time! I felt that. Also, I don't think there are many cases where Python runs on Windows, but I tried it because it was a big deal, and it worked, so I added it.

The run-time parameters <prefix> and <file> are songwriters, and as you can see, the file wasn't uploaded as intended at first, which was a bit difficult to understand. For example, if you specify the full path for <file>,

/tmp/upload/test.txt   Mar 03, 2020 at 21:21:50   20 B

A file with the path name will be uploaded. So, moving to the directory of the file you want to send and calling cos-upload.py from there does not have to be tricky, so it may be easier to do. I think.

Reference link

--Upload and publish files to IBM Cloud Object Storage (ICOS) with curl command -Upload files to IBM Cloud Object Storage (ICOS) using CLI (ibmcloud command) -Upload files to Aspera that comes with IBM Cloud Object Storage (ICOS) using SDK (Java version)

Recommended Posts

Upload files to Aspera that comes with IBM Cloud Object Storage (ICOS) using SDK (Python version)
Convert the cURL API to a Python script (using IBM Cloud object storage)
Upload file to GCP's Cloud Storage (GCS) ~ Load with local Python
How to upload a file to Cloud Storage using Python [Make a fixed point camera with Raspberry PI # 1]
[Cloudian # 1] Try to access object storage with AWS SDK for Python (boto3)
Convert files uploaded to Cloud Storage with Cloud Functions (Python) so that they are not garbled in Excel
Upload files to Google Drive with Lambda (Python)
[Python] Change the Cache-Control of the object uploaded to Cloud Storage
Cloud Functions to resize images using OpenCV with Cloud Storage triggers
Upload and delete files to Google Cloud Storages with django-storage
Changes to run "Using Cloud Dataflow + Cloud Pub / Sub + Fluentd ..." with SDK 2.1
Image upload & download to Azure Storage. With Python + requests + REST API
Regularly upload files to Google Drive using the Google Drive API in Python
File upload to Azure Storage (Python)
[Cloudian # 3] Try to create a new object storage bucket with Python (boto3)
Convert the spreadsheet to CSV and upload it to Cloud Storage with Cloud Functions
Copy data from Amazon S3 to Google Cloud Storage with Python (boto)
Try to poke DB on IBM i with python + JDBC using JayDeBeApi
GAE --With Python, rotate the image based on the rotation information of EXIF and upload it to Cloud Storage.
[AWS] Using ini files with Lambda [Python]
Try using Python with Google Cloud Functions
Working with OpenStack using the Python SDK
[GCP] Operate Google Cloud Storage with Python
Convert HEIC files to PNG files with Python
Operate Sakura's cloud object storage from Python
Upload images to Google Drive with Python
Study from Python Reading and writing Hour9 files
Reading and writing csv files
Upload files to Aspera that comes with IBM Cloud Object Storage (ICOS) using SDK (Python version)
Install Anaconda on Mac and upload Jupyter (IPython) notebook to Anaconda Cloud
How to fix the shit heavy when reading Google Cloud Storage images from Django deployed on GAE
Settings when reading S3 files with pandas from Jupyter Notebook on AWS
Reading and writing JSON files with Python
Operate Sakura's cloud object storage from Python
[IBM Cloud] I tried to access the Db2 on Cloud table from Cloud Funtions (python)
How to install Fast.ai on Alibaba Cloud GPU and run it on Jupyter notebook
Convert the cURL API to a Python script (using IBM Cloud object storage)
Try using Dropbox API v2 with Go
[Cloudian # 1] Try to access object storage with AWS SDK for Python (boto3)
Fleet provisioning with AWS IoT SDK for Python v2
Using Lambda with AWS Amplify with Go
Upload and download images with falcon
Let's try gRPC with Go and Docker
[AWS] Link Lambda and S3 with boto3
Join Azure Using Go ~ For those who want to start and know Azure with Go ~
Upload images to S3 with GUI using tkinter
Learn Service Bus Queue with Azure SDK for Go (1)
Try a similar search for Image Search using the Python SDK [Search]
Try MD simulation with ANN potential using aenet and ASE
Try automating Start / Stop for EC2 instances with AWS Lambda
This and that for using Step Functions with CDK + Python
Upload files to Aspera that comes with IBM Cloud Object Storage (ICOS) using SDK (Python version)