cannot add path of a folder stored in google drive - python-3.x

Subfolder 'gdrive' from the folder 'content' is not being recognized. This image is the screenshot of the error
No such file or folder exists :

you need to use the id of the google drive folder. google drive folder are accessible by their ids not names.
here is how you find the id of the folder link

You need a leading / in your path. For example, run:
from google.colab import drive
drive.mount('/content/gdrive')
%cd /content/gdrive

Related

How to get the file link from a SharePoint/OneDrive Sync location

I am currently using Registry Editor to obtain the cloud OneDrive URL of a local OneDrive folder, through:
HKEY_CURRENT_USER\SOFTWARE\SyncEngines\Providers\OneDrive\ -> UrlNameSpace.
However, for shared folders I cannot seem to obtain the correct path based on the UrlNameSpace property. For example the following below returns:
C: Drive path (MountPoint) - C:\Users\nathan.hurley\MyCompany\John Smith - ShareFolder
(UrlNameSpace) - https://mycompany.sharepoint.com/personal/john_smith_mycompany_com/Documents
Following the example above, if I'm trying to get the cloud OneDrive URL for:
C:\Users\nathan.hurley\MyCompany\John Smith - ShareFolder\Test
Replacing the C: Drive path with the UrlNameSpace will produce the following path:
https://mycompany.sharepoint.com/personal/john_smith_mycompany_com/Documents/Test.
The problem with this online link, is that it doesn't obtain the root synced folder and opening the link will lead to a 404 page error. The correct URL should be the following:
https://mycompany.sharepoint.com/personal/john_smith_mycompany_com/Documents/ShareFolder/Test
Again, I've noticed this issue only occurs with shared folders and within the Registry Editor, these folders also include an additional property called IsFolderScope. Is there an efficient way to determine which folders are Shared Folders other than checking the IsFolderScope property? Also, are shared folders the only folders that include this property?
Reference: https://tdalon.blogspot.com/2020/12/get-url-from-sync.html

Correctly enter the site_ID using Graph SDK

Regarding this expression to create a folder:
POST /sites/{site-id}/drive/items/{parent-item-id}/children
What is the correct way to enter the {site-id} and the {parent-item-id}, to access a folder (eg:folder_1) in a site (eg: site1)in a domain (eg: mydomain)
I have tried:
POST /sites/mydomain/drive/items/site1/folder_1/children
POST /sites:/mydomain/site1:/drive/items/folder_1/children
and similar, with no success,
Can you help me please?
THanks for the help.
Follow your steps, but In the second step, you say:
"This is the sub folder named "2019" in default Documents library:"
With this, I can acess the shared documents folder inside the site. I don't want to acess that folder. I need to acess another folder that is in the site, but not inside the share documents folder.
Any clue?
Do a get request like this in Graph Explorer with this request:
https://graph.microsoft.com/v1.0/sites/<host>:<server relative url>
Example:
https://graph.microsoft.com/v1.0/sites/zheguo.sharepoint.com:/sites/dev
Then will return site Id
Update if you want to access other library folder in Graph, firstly get drive id with this endpoint:
https://graph.microsoft.com/v1.0/sites/{site-id}/drives
Then access the specific drive folder with this endpoint:
https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}
Then for "parent-item-id", it's the specific folder id in document library, you can get with this endpoint:
https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/items/root:
Example:
https://graph.microsoft.com/v1.0/sites/zheguo.sharepoint.com,91a47a59-db5e-4d17-a689-479ee8905533,274459c9-4c96-42bf-9b96-838ffa387aaa/drives/b!WXqkkV7bF02miUee6JBVM8lZRCeWTL9Cm5aDj_o4eqpLdqmLE2R7QosYOZt8Dyao/items/root:/
Then use the endpoint to create folder:
POST /sites/{site-id}/drives/{drive-id}/items/{parent-item-id}/children
Example:
https://graph.microsoft.com/v1.0/sites/zheguo.sharepoint.com,91a47a59-db5e-4d17-a689-479ee8905533,274459c9-4c96-42bf-9b96-838ffa387aaa/drive/items/01WU7SPCC4FNS6KOYTSJFK2MUFRITF5XQL/children
Reference:
Create a new folder in a drive

How to download large files (like weights of a model) from Colaboratory?

I have tried downloading small files from google Colaboratory. They are easily downloaded but whenever I try to download files which have a large sizes it shows an error? What is the way to download large files?
If you have created a large zip file, say my_archive.zip, then you can download it as following:
Mount your Google drive from your Google colab Notebook. You will
be asked to enter a authentication code.
from google.colab import drive
drive.mount('/content/gdrive',force_remount=True)
Copy the zip file to any of your google drive folder (e.g. downloads folder). You may also copy the file on 'My Drive' which is a root folder.
!cp my_archive.zip '/content/gdrive/My Drive/downloads/'
!ls -lt '/content/gdrive/My Drive/downloads/'
Finally, you can download the zip file from your Google drive to your local machine.
This is how I handle this issue:
from google.colab import auth
from googleapiclient.http import MediaFileUpload
from googleapiclient.discovery import build
auth.authenticate_user()
Then click on the link, authorize Google Drive and paste the code in the notebook.
drive_service = build('drive', 'v3')
def save_file_to_drive(name, path):
file_metadata = {
'name': name,
'mimeType': 'application/octet-stream'
}
media = MediaFileUpload(path,
mimetype='application/octet-stream',
resumable=True)
created = drive_service.files().create(body=file_metadata,
media_body=media,
fields='id').execute()
print('File ID: {}'.format(created.get('id')))
return created
Then:
save_file_to_drive(destination_name, path_to_file)
This will save whatever files to your Google Drive, where you can download or sync them or whatever.
I tried many different solutions. The only way that was effective and quick is to zip the file/folder and then download it directly:
!zip -r model.zip model.pkl
And to download:
Google colab doesn't allow you to download large files using files.download(). But you can use one of the following methods to access it:
The easiest one is to use github to commit and push your files and then clone it to your local machine.
You can mount google-drive to your colab instance and write the files there.

Cant access images one directory back

I am using linux server and I am using absolute path for files which is stored in a "constant"
File path is
/home1/mousi1/public_html/xyz/data/1465221530.png
Image is loading when I access file which is on home directory like
/home1/mousi1/public_html/xyz/file.php
but when I try
/home1/mousi1/public_html/xyz/subdirectory/file.php
Path is still
/home1/mousi1/public_html/xyz/data/1465221530.png
but image is not showing I am wondering why is it?
What is wrong?

CodeIgniter - Directory Traversal - sanitize_filename()

If I use the CodeIgniter File Upload Class and rename the image being uploaded using:
$config['file_name']
do I still have to use
$this->security->sanitize_filename()
on the image being uploaded by user?
just set $config['encrypt_name']; will automatically rename users uploaded file or image for more information check user guide of File uploading library
File Upload Library

Resources