Transfer videos from Dropbox to Storj
Use this guide to encode your Dropbox videos and export them to a Storj bucket.
1. Get a ByteNite access token
To begin, use your API key to obtain an access token.
Saved variables:
Variable | Value |
---|---|
access_token | Your ByteNite access token |
2. Get a Dropbox access token
Follow this guide to learn how to obtain an access token from Dropbox and set up the ByteNite-Dropbox connector:
Saved variables:
Variable | Value |
---|---|
dropbox_access_token | Your Dropbox access token |
3. Get your Storj access and secret keys
Get a pair of S3-compatible keys from Storj with at least write access to your destination bucket. You can learn how to get your Storj credentials here:
Saved variables:
Variable | Value |
---|---|
storj_access | Your Storj S3-compatible access key |
storj_secret | Your Storj S3-compatible secret key |
4. Pick a Dropbox input folder
Choose or create a Dropbox folder where your input videos are stored and save its path to the variable dropbox_path
. Next, call the Dropbox API to obtain the IDs of the video files contained in that folder.
import mimetypes
# Define Dropbox input folder path
dropbox_path = "/Input Videos"
# Define headers for API request
headers = {
"Authorization": f"Bearer {dropbox_access_token}",
"Content-Type": "application/json"
}
# Define data for API request
data = {
"include_deleted": False,
"include_has_explicit_shared_members": False,
"include_media_info": True,
"include_mounted_folders": False,
"include_non_downloadable_files": False,
"path": dropbox_path,
"recursive": False
}
# Send API request to list folder contents
response = requests.post("https://api.dropboxapi.com/2/files/list_folder",
headers=headers, json=data)
response.raise_for_status()
# Filter video files and create a list of ID-path pairs
dropbox_videos = [{'id':item['id'], 'path':item['path_display']} for item in response.json()['entries'] if item['.tag'] == 'file' and 'video' in mimetypes.guess_type(item['name'])[0]]
Saved variables:
Variable | Value |
---|---|
dropbox_videos | A list of Dropbox videos ID-path pairs |
5. Pick a Storj destination folder
Create the request body for your data destination by specifying a Storj bucket, a folder path, a cloud region, and your access and secret keys, according to the Storj Data Destination guide.
Saved variables:
Variable | Value |
---|---|
data_destination | The JSON with your data destination parameters |
6. Load video encoding parameters
Choose a video encoding template from our Templates or build your own and load it into the job_parameters
variable.
Saved variables:
Variable | Value |
---|---|
job_parameters | The JSON with your video encoding parameters |
7. Create and launch your jobs
Create as many jobs as your input videos. Attach to your request the Dropbox data source with the specific file ID of each video, and the data destination body created in the step above. In addition, attach the job parameters imported in the step above, and the job name of each job.
i = 0
# Create one job for each input video
for video in dropbox_videos:
i += 1
# Define data source for the current video
data_source = {
"dataSourceDescriptor": "dropbox",
"params": {
"@type": "type.googleapis.com/bytenite.data_source.DropboxDataSource",
"id": video['id']
}
}
# Extract job name from video path
job_name = os.path.split(os.path.splitext(video['path'])[0])[1]
# Create a new job body
new_job_body = {
"templateId": "[email protected]",
"name": job_name,
"dataSource": data_source,
"dataDestination": data_destination,
"params": job_parameters
}
# Create a new job
response = requests.post('http://api.bytenite.com/v1/customer/jobs',
json=new_job_body,
headers={'Authorization': access_token})
try:
response.raise_for_status()
job_id = response.json()['job']['id']
print(f"Job #{i} ({job_name}) created - ID: {job_id}")
except:
print(f"CREATE ERROR: Job #{i} ({job_name}): {response}")
continue
# Start the job
response = requests.post(f'https://api.bytenite.com/v1/customer/jobs/run/{job_id}',
headers={'Authorization': access_token})
try:
response.raise_for_status()
print(f"Job #{i} ({job_name}) started")
except:
print(f"RUN JOB ERROR: Job #{i} ({job_name}): {response}")
That's it! Now check your Storj bucket to confirm your outputs.
8. Optional: delete your videos from Dropbox
If you no longer want to keep your input videos on Dropbox, you can delete them with the following command:
# Define headers for API request
headers = {
"Authorization": f"Bearer {dropbox_access_token}",
"Content-Type": "application/json"
}
# Send API request to delete videos
response = requests.post("https://api.dropboxapi.com/2/files/delete_batch",
headers=headers,
json={"entries": [{"path": video["path"]} for video in dropbox_videos]})
Updated 9 months ago