I want to find a free cloud storage service with free API, that could help me back up some files automatically.
I want to write some script (for example python) to upload files automatically.
I investigated OneDrive and GoogleDrive. OneDrive API is not free, GoogleDrive API is free while it need human interactive authorization before using API.
For now I'm simply using email SMTP protocol to send files as email attachments, but there's a max file size limition, which will fail me in the future, as my file size is growing.
Is there any other recommendations ?
I believe your goal as follows.
At first, in your situation, how about using google-api-python-client? In this answer, I would like to explain the following flow and the sample script using google-api-python-client.
Please create the service account and download a JSON file. Ref
google-api-python-client
.In order to use the sample script, please install google-api-python-client
.
$ pip install google-api-python-client
Please create a new folder in your Google Drive. And, please share the created folder with the email of your service account. Because the Google Drive of your account is different from the Drive of service account. By sharing the folder with the service account, the file can be uploaded to the folder in your Google Drive using the service account. By this, you can see the uploaded file on your Google Drive by your browser.
Please set the filename of credentials of service account, the filename of the file you want to upload and the folder ID of folder you shared your folder with the service account to the variables of SERVICE_ACCOUNT
, UPLOAD_FILE
and FOLDER_ID
, respectively.
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
SERVICE_ACCOUNT = '###' # Please set the file of your credentials of service account.
UPLOAD_FILE = 'sampleFilename' # Please set the filename with the path you want to upload.
FOLDER_ID = '###' # Please set the folder ID that you shared your folder with the service account.
FILENAME = 'sampleFilename' # You can set the filename of the uploaded file on Google Drive.
SCOPES = ['https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name(SERVICE_ACCOUNT, SCOPES)
drive = build('drive', 'v3', credentials=credentials)
metadata = {'name': FILENAME, "parents": [FOLDER_ID]}
file = MediaFileUpload(UPLOAD_FILE, resumable=True)
response = drive.files().create(body=metadata, media_body=file).execute()
fileId = response.get('id')
print(fileId) # You can see the file ID of the uploaded file.
file = MediaFileUpload(UPLOAD_FILE, resumable=True)
to file = MediaFileUpload(UPLOAD_FILE, mimeType='###', resumable=True)
.