Transferring Files (Recommended)
Through file transferring, local files and folders can be uploaded to OBS, and the files and folders in OBS can be downloaded to a local path.
Sample Code
In ModelArts notebook, you do not need to enter authentication parameters for session authentication. For details about session authentication of other development environments, see Session Authentication.
from modelarts.session import Session session = Session() # 1. Upload a local file to OBS. session.obs.copy(src_path='/home/ma-user/file1.txt', dst_path='obs://bucket-name/dir1/file1.txt') # 2. Download a file from OBS to a local path. session.obs.copy(src_path='obs://bucket-name/dir1/file1.txt', dst_path='/home/ma-user/file1.txt') # 3. Upload a local folder to OBS. session.obs.copy(src_path='/home/ma-user', dst_path='obs://bucket-name/dir1', keep_last_dir=True) # 4. Download a folder from OBS to a local path. session.obs.copy(src_path='obs://bucket-name/dir1', dst_path='/home/ma-user', keep_last_dir=True)
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
session |
Yes |
Object |
Session object. |
src_path |
Yes |
String |
Path to the source file or folder. If the source path is an OBS path, the path prefix must be obs://. |
dst_path |
Yes |
String |
Path to the destination file or folder. If the destination path is an OBS path, the path prefix must be obs://. |
keep_last_dir |
No |
Boolean |
Whether to copy the last-level directory of the source folder to the destination folder. The default value is True. This parameter is valid only for copying folders. |
Parameter |
Type |
Description |
---|---|---|
error_code |
String |
Error code when calling the SDK failed. This parameter is unavailable for a successful call. |
error_msg |
String |
Error message when calling the SDK failed. This parameter is unavailable for a successful call. |
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