Uploading and Downloading a File in a Notebook
In a notebook instance, you can call APIs to exchange data with OBS for uploading a file to OBS or downloading a file from OBS to the notebook instance.
For details about how to upload a file using OBS Browser+, see Uploading a File.
Using SDK to Upload and Download a File
Download a file from OBS to a notebook instance.
Sample code: Download file1.txt from OBS to /home/ma-user/work/ in the notebook instance. The bucket name, folder name, and file name are customizable.
from modelarts.session import Sessionsession = Session()session.obs.download_file(src_obs_file="obs://bucket-name/dir1/file1.txt", dst_local_dir="/home/ma-user/work/")
Download a folder from OBS to a notebook instance.
Sample code: Download dir1 from OBS to /home/ma-user/work/ in the notebook instance. The bucket name and folder name are customizable.
from modelarts.session import Sessionsession = Session()session.obs.download_dir(src_obs_dir="obs://bucket-name/dir1/", dst_local_dir="/home/ma-user/work/")
Upload a file from a notebook instance to OBS.
Sample code: Upload file1.txt in the notebook instance to OBS bucket obs://bucket-name/dir1/. The bucket name, folder name, and file name are customizable.
from modelarts.session import Sessionsession = Session()session.obs.upload_file(src_local_file='/home/ma-user/work/file1.txt', dst_obs_dir='obs://bucket-name/dir1/')
Upload a folder from a notebook instance to OBS.
Sample code: Upload /work/ in the notebook instance to obs://bucket-name/dir1/work/ of bucket-name. The bucket name and folder name are customizable.
from modelarts.session import Sessionsession = Session()session.obs.upload_dir(src_local_dir='/home/ma-user/work/', dst_obs_dir='obs://bucket-name/dir1/')
Troubleshooting
If you download a file from OBS to your notebook instance and the system displays error message "Permission denied", perform the following operations for troubleshooting:
- Ensure that the OBS bucket to be read is in the same region as the notebook instance. You cannot access an OBS bucket in another region. For details, see Checking Whether an OBS Bucket and DataArts Studio Are in the Same Region.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot