### Install Quasar CLI and Vue CLI Source: https://transloadit.com/blog/2018/12/2h-youtube-clone Commands to install the Vue CLI and Quasar CLI globally. These are prerequisites for creating a new Quasar project. ```bash # Install the Vue CLI globally npm install -g vue-cli # Install the quasar CLI globally npm install -g quasar-cli ``` -------------------------------- ### Assembly Instructions Example Source: https://transloadit.com/docs/topics/assembly-instructions This example demonstrates a typical Transloadit assembly process, including uploading, importing, resizing, and storing files. ```APIDOC ## POST /assemblies ### Description This endpoint allows you to create and configure an assembly for file processing. Assemblies are defined by a set of steps, each utilizing a specific robot to perform an operation. ### Method POST ### Endpoint /assemblies ### Parameters #### Request Body - **steps** (object) - Required - An object defining the sequence of operations (robots) to be performed. Each key is a step name, and the value is an object with robot instructions. - **":original"** (object) - Special key for uploaded files, uses the `/upload/handle` robot. - **"imported_watermark"** (object) - Example step using `/http/import` robot to fetch a remote file. - **robot** (string) - `/http/import` - **url** (string) - URL of the file to import. - **"resized"** (object) - Example step using `/image/resize` robot. - **robot** (string) - `/image/resize` - **use** (object | Array | Array | string) - Specifies input steps. Example: `{"steps": [{"name": ":original", "as": "base"}, {"name": "imported_watermark", "as": "watermark"}]}` - **width** (integer) - Desired width for resizing. - **height** (integer) - Desired height for resizing. - **watermark_position** (string) - Position of the watermark. - **watermark_size** (string) - Size of the watermark. - **"exported"** (object) - Example step using `/s3/store` robot. - **robot** (string) - `/s3/store` - **use** (Array | object) - Steps to use as input. Example: `[":original", "resized"]` - **credentials** (string) - S3 storage credentials. - **path** (string) - Path for storing the file on S3, supports variables like `${file.id}` and `${file.url_name}`. ### Request Example ```json { "steps": { ":original": { "robot": "/upload/handle" }, "imported_watermark": { "robot": "/http/import", "url": "https://transloadit.com/assets/images/face.jpg" }, "resized": { "robot": "/image/resize", "use": { "steps": [ { "name": ":original", "as": "base" }, { "name": "imported_watermark", "as": "watermark" } ] }, "width": 400, "height": 400, "watermark_position": "center", "watermark_size": "30%" }, "exported": { "robot": "/s3/store", "use": [":original", "resized"], "credentials": "my_cloud_storage_credentials", "path": "/my_images/${file.id}/${file.url_name}" } } } ``` ### Response #### Success Response (200) - **assembly_id** (string) - The unique identifier for the created assembly. - **url** (string) - The URL to poll for assembly status updates. #### Response Example ```json { "assembly_id": "abc123xyz789", "url": "/assemblies/abc123xyz789" } ``` ``` -------------------------------- ### Install Uppy and Related Libraries Source: https://transloadit.com/blog/2018/12/2h-youtube-clone NPM command to install Uppy core, its dashboard, and various plugins (Dropbox, Google Drive, Instagram, URL, Transloadit, Webcam). Also installs plyr for video playback and vue-disqus for comments. ```bash npm install --save @uppy/core @uppy/dashboard @uppy/dropbox @uppy/google-drive @uppy/instagram @uppy/transloadit @uppy/url @uppy/webcam plyr vue-disqus ``` -------------------------------- ### File Preview API - Usage Example Source: https://transloadit.com/blog/2024/06/file-preview-with-smart-cdn This example demonstrates how to use the File Preview API via the Smart CDN, including common parameters for resizing and formatting. ```APIDOC ## GET /file/preview ### Description This endpoint allows you to generate previews for various file types, including images, videos, audio, documents, web pages, and archives. It supports on-the-fly processing such as resizing, reformatting, and cropping. ### Method GET ### Endpoint `https://.tlcdn.com/?input=&w=&h=&f=&r=` ### Query Parameters - **input** (string) - Required - The path to the input file. - **w** (integer) - Optional - The desired width of the preview. - **h** (integer) - Optional - The desired height of the preview. - **f** (string) - Optional - The desired output format (e.g., 'png', 'jpg', 'gif'). Defaults to 'png'. - **r** (string) - Optional - The resize strategy (e.g., 'pad', 'crop', 'max'). Defaults to 'pad'. - **sig** (string) - Optional - Signature for authentication. - **exp** (string) - Optional - Expiration time for signed URLs. ### Request Example ``` https://my-app.tlcdn.com/preview?input=audio.mp3&w=240&h=240&f=png&r=pad ``` ### Response #### Success Response (200) Returns the generated preview image or a file type icon if a preview cannot be generated. #### Response Example (Binary image data or icon) ``` -------------------------------- ### JavaScript SDK Example for Smart CDN URL Source: https://transloadit.com/docs/api/authentication An example demonstrating how to use the Transloadit JavaScript SDK to generate a signed Smart CDN URL. ```APIDOC ## JavaScript SDK Example ### Description This code snippet shows how to use the Transloadit JavaScript SDK to generate a signed Smart CDN URL. Ensure you have installed the SDK using `yarn add transloadit` or `npm install --save transloadit`. ### Method N/A (SDK function) ### Endpoint N/A (SDK function) ### Parameters #### Request Body (Implicit via SDK function parameters) - **workspace** (string) - Your Transloadit Workspace name. - **template** (string) - The name of your Transloadit Template. - **input** (string) - The path to the file you want to transform. - **urlParams** (object) - An object containing desired transformation parameters (e.g., `{ height: 100, width: 100 }`). ### Request Example ```javascript import { Transloadit } from 'transloadit' const transloadit = new Transloadit({ authKey: 'YOUR_TRANSLOADIT_KEY', authSecret: 'YOUR_TRANSLOADIT_SECRET', }) const url = transloadit.getSignedSmartCDNUrl({ workspace: 'YOUR_WORKSPACE', template: 'YOUR_TEMPLATE', input: 'image.png', urlParams: { height: 100, width: 100 }, }) console.log(url) ``` ### Response #### Success Response - **url** (string) - The generated signed Smart CDN URL. #### Response Example ``` https://[your-workspace].tlcdn.com/[template-name]/image.png?height=100&width=100&exp=...&auth_key=...&sig=sha256:... ``` ``` -------------------------------- ### Create Assembly with Video Steps (PHP) Source: https://transloadit.com/demos/video-encoding/concatenate-fade-effect Illustrates how to initiate a Transloadit assembly using the PHP SDK. It defines steps for uploading, importing, resizing, concatenating, and encoding videos, similar to the Ruby example. ```php "YOUR_TRANSLOADIT_KEY", "secret" => "YOUR_TRANSLOADIT_SECRET", ]); // Start the Assembly $response = $transloadit->createAssembly([ "files" => ["kite10.mp4"], "params" => [ "steps" => [ ":original" => [ "robot" => "/upload/handle", ], "preroll_imported" => [ "robot" => "/http/import", "result" => true, "url" => "https://demos.transloadit.com/inputs/waves10.mp4", ], "preroll_resized" => [ "robot" => "/video/encode", "use" => "preroll_imported", "result" => true, "ffmpeg_stack" => "v7.0.0", "preset" => "ipad-high", "width" => 480, "height" => 270, "resize_strategy" => "pad", "background" => "#00000000", "turbo" => false, ], "original_resized" => [ "robot" => "/video/encode", "use" => ":original", "result" => true, "ffmpeg_stack" => "v7.0.0", "preset" => "ipad-high", "width" => 480, "height" => 270, "resize_strategy" => "pad", "background" => "#00000000", "turbo" => false, ], "concatenated" => [ "use" => [ "steps" => [ [ "name" => "original_resized", "as" => "video_1", ], , [ "name" => "preroll_resized", "as" => "video_2", ], ], ], "robot" => "/video/concat", "result" => true, "ffmpeg_stack" => "v7.0.0", "preset" => "ipad-high", "video_fade_seconds" => 1, "audio_fade_seconds" => 1, ], "encode" => [ "use" => "concatenated", ``` -------------------------------- ### JSON Assembly Configuration Example Source: https://transloadit.com/docs/topics/assembly-instructions This JSON configuration defines a Transloadit assembly process with multiple steps. It includes uploading, importing a watermark, resizing an image with the watermark, and storing the results on S3. This example demonstrates step bundling and the use of variables for dynamic paths. ```json { "steps": { ":original": { "robot": "/upload/handle" }, "imported_watermark": { "robot": "/http/import", "url": "https://transloadit.com/assets/images/face.jpg" }, "resized": { "robot": "/image/resize", "use": { "steps": [ { "name": ":original", "as": "base" }, { "name": "imported_watermark", "as": "watermark" } ] }, "width": 400, "height": 400, "watermark_position": "center", "watermark_size": "30%" }, "exported": { "robot": "/s3/store", "use": [":original", "resized"], "credentials": "my_cloud_storage_credentials", "path": "/my_images/${file.id}/${file.url_name}" } } } ``` -------------------------------- ### Create Transloadit Assembly with Node.js SDK Source: https://transloadit.com/demos/document-processing/convert-all-pages-of-a-document-into-an-animated-gif This example demonstrates how to initialize the Transloadit SDK in Node.js and create an assembly with specified encoding steps. It requires your Transloadit API keys. ```javascript // npm install transloadit // Import import { Transloadit } from 'transloadit' const main = async () => { // Init const transloadit = new Transloadit({ authKey: 'YOUR_TRANSLOADIT_KEY', authSecret: 'YOUR_TRANSLOADIT_SECRET', }) // Set Encoding Instructions const options = { files: { myfile_1: './bitcoin.pdf', }, params: { steps: { ':original': { robot: '/upload/handle', }, thumbnailed: { use: ':original', robot: '/document/thumbs', result: true, width: 100, height: 250, delay: 50, trim_whitespace: false, resize_strategy: 'fit', background: '#000000', format: 'gif', }, exported: { use: ['thumbnailed', ':original'], robot: '/s3/store', credentials: 'demo_s3_credentials', url_prefix: 'https://demos.transloadit.com/', }, }, }, } // Execute const result = await transloadit.createAssembly(options) // Show results console.log({ result }) } main().catch(console.error) ``` -------------------------------- ### Create Quasar Project Source: https://transloadit.com/blog/2018/12/2h-youtube-clone Command to initialize a new Quasar project named 'youtube_clone_client'. Follow the prompts to configure the project. ```bash quasar init youtube_clone_client ``` -------------------------------- ### Example IAM Policy for Transloadit S3 Access Source: https://transloadit.com/docs/robots/s3-store This JSON policy grants Transloadit the minimum required permissions to store files in your S3 bucket. It includes actions for getting bucket location, listing buckets, putting objects, and setting object ACLs. Ensure you replace `{BUCKET_NAME}` with your actual bucket name. ```json { "Version": "2012-10-17", "Statement": [ { "Sid": "AllowTransloaditToStoreFilesIn{BUCKET_NAME}Bucket", "Effect": "Allow", "Action": ["s3:GetBucketLocation", "s3:ListBucket", "s3:PutObject", "s3:PutObjectAcl"], "Resource": ["arn:aws:s3:::{BUCKET_NAME}", "arn:aws:s3:::{BUCKET_NAME}/*"] } ] } ``` -------------------------------- ### Export to S3 using Transloadit Go SDK Source: https://transloadit.com/demos/document-processing/convert-all-pages-of-a-document-into-an-animated-gif Illustrates how to set up and initiate an assembly for S3 export using the Transloadit Go SDK. This involves configuring the client, defining assembly steps including the S3 store robot, and adding files for upload. Ensure the Go SDK is installed. ```go package main import ( "context" "fmt" "github.com/transloadit/go-sdk" ) func main() { // Create client options := transloadit.DefaultConfig options.AuthKey = "YOUR_TRANSLOADIT_KEY" options.AuthSecret = "YOUR_TRANSLOADIT_SECRET" client := transloadit.NewClient(options) // Initialize new Assembly assembly := transloadit.NewAssembly() // Set Encoding Instructions assembly.AddStep(":original", map[string]interface{}{ "robot": "/upload/handle", }) assembly.AddStep("thumbnailed", map[string]interface{}{ "use": ":original", "robot": "/document/thumbs", "result": true, "width": 100, "height": 250, "delay": 50, "trim_whitespace": false, "resize_strategy": "fit", "background": "#000000", "format": "gif", }) assembly.AddStep("exported", map[string]interface{}{ "use": ["thumbnailed", ":original"], "robot": "/s3/store", "credentials": "demo_s3_credentials", "url_prefix": "https://demos.transloadit.com/", }) ``` -------------------------------- ### Python SDK: Video Encoding and Concatenation Assembly Source: https://transloadit.com/demos/video-encoding/concatenate-fade-effect This Python code snippet demonstrates how to configure a Transloadit assembly for video processing using the Python SDK. It mirrors the functionality of the Go example, including importing, resizing, concatenating, encoding with fade effects, and storing to S3. Ensure you have installed the SDK using 'pip install pytransloadit'. ```python from transloadit import client t = client.Transloadit('YOUR_TRANSLOADIT_KEY', 'YOUR_TRANSLOADIT_SECRET') assembly = tl.new_assembly() # Set Encoding Instructions assembly.add_step(":original", "/upload/handle", {}) assembly.add_step("preroll_imported", "/http/import", { 'result': True, 'url': 'https://demos.transloadit.com/inputs/waves10.mp4' }) assembly.add_step("preroll_resized", "/video/encode", { 'use': 'preroll_imported', 'result': True, 'ffmpeg_stack': 'v7.0.0', 'preset': 'ipad-high', 'width': 480, 'height': 270, 'resize_strategy': 'pad', 'background': '#00000000', 'turbo': False }) assembly.add_step("original_resized", "/video/encode", { 'use': ':original', 'result': True, 'ffmpeg_stack': 'v7.0.0', 'preset': 'ipad-high', 'width': 480, 'height': 270, 'resize_strategy': 'pad', 'background': '#00000000', 'turbo': False }) assembly.add_step("concatenated", "/video/concat", { 'use': { 'steps': [ { 'name': 'original_resized', 'as': 'video_1' }, { 'name': 'preroll_resized', 'as': 'video_2' } ] }, 'result': True, 'ffmpeg_stack': 'v7.0.0', 'preset': 'ipad-high', 'video_fade_seconds': 1, 'audio_fade_seconds': 1 }) assembly.add_step("encode", "/video/encode", { 'use': 'concatenated', 'preset': 'empty', 'ffmpeg': { 'vf': 'fade=type=in:duration=1' }, 'ffmpeg_stack': 'v7.0.0', 'turbo': False }) assembly.add_step("exported", "/s3/store", { 'use': ['preroll_imported', 'preroll_resized', 'original_resized', 'concatenated', 'encode', ':original'], 'credentials': 'demo_s3_credentials', 'url_prefix': 'https://demos.transloadit.com/' }) # Add files to upload assembly.add_file(open('kite10.mp4', 'rb')) # Start the Assembly # The following lines to start and wait for the assembly are omitted for brevity # but would be similar to the Go SDK example. ``` -------------------------------- ### Encode audio to MP3 with FFmpeg fade effects using Transloadit Source: https://transloadit.com/demos/audio-encoding/ffmpeg-fade-in-and-out This example demonstrates encoding an audio file to MP3 using Transloadit's `ffmpeg` parameter. It specifically utilizes `afade` for fade-in and fade-out effects, `st` to define the start time of the fade, `d` for fade duration, and `to` to trim the file to a specific length. The `mp3` preset is also applied. ```json { "robot": "/video/encode", "use": [ "mp3" ], "ffmpeg": [ { "af": "afade=t=in:st=0:d=5,afade=t=out:st=235:d=5", "to": "245" } ] } ``` -------------------------------- ### Initialize Transloadit Client and Create Assembly in Go Source: https://transloadit.com/demos/video-encoding/add-text-overlay Demonstrates how to initialize the Transloadit client with API keys and create a new assembly. It includes setting up encoding steps for video overlays and storing the results using the Go SDK. Dependencies include the 'go-sdk' package. ```go // go get gopkg.in/transloadit/go-sdk.v1 package main import ( "context" "fmt" "github.com/transloadit/go-sdk" ) func main() { // Create client options := transloadit.DefaultConfig options.AuthKey = "YOUR_TRANSLOADIT_KEY" options.AuthSecret = "YOUR_TRANSLOADIT_SECRET" client := transloadit.NewClient(options) // Initialize new Assembly assembly := transloadit.NewAssembly() // Set Encoding Instructions assembly.AddStep(":original", map[string]interface{}{ "robot": "/upload/handle", }) assembly.AddStep("text_overlay_default", map[string]interface{}{ "use": ":original", "robot": "/video/encode", "preset": "empty", "ffmpeg": map[string]interface{}{ "codec:a": "copy", "vf": "drawtext=text='My text overlay':fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2", }, "result": true, "ffmpeg_stack": "v7.0.0", }) assembly.AddStep("text_overlay_custom", map[string]interface{}{ "use": ":original", "robot": "/video/encode", "preset": "empty", "ffmpeg": map[string]interface{}{ "codec:a": "copy", "vf": "drawtext=font='Times New Roman':text='My text overlay':fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2", }, "result": true, "ffmpeg_stack": "v7.0.0", }) assembly.AddStep("exported", map[string]interface{}{ "use": ["text_overlay_default", "text_overlay_custom", ":original"], "robot": "/s3/store", "credentials": "demo_s3_credentials", "url_prefix": "https://demos.transloadit.com/", }) // Add files to upload assembly.AddFile("surf.mp4") // Start the Assembly info, err := client.StartAssembly(context.Background(), assembly) if err != nil { panic(err) } // All files have now been uploaded and the Assembly has started but no // results are available yet since the conversion has not finished. // WaitForAssembly provides functionality for polling until the Assembly // has ended. info, err = client.WaitForAssembly(context.Background(), info) if err != nil { panic(err) } fmt.Printf("You can check some results at: ") fmt.Printf(" - %s\n", info.Results[":original"][0].SSLURL) fmt.Printf(" - %s\n", info.Results["text_overlay_default"][0].SSLURL) fmt.Printf(" - %s\n", info.Results["text_overlay_custom"][0].SSLURL) fmt.Printf(" - %s\n", info.Results["exported"][0].SSLURL) } ``` -------------------------------- ### S3 Bucket IAM Policy for Transloadit Access Source: https://transloadit.com/docs/robots/s3-import An example AWS IAM policy granting Transloadit the minimum required permissions to access an S3 bucket. This policy allows Transloadit to list the bucket contents and retrieve objects. Ensure you replace `{BUCKET_NAME}` with your actual bucket name and consider using a dedicated IAM user for enhanced security. ```json { "Version": "2012-10-17", "Statement": [ { "Sid": "AllowTransloaditToImportFilesIn{BUCKET_NAME}Bucket", "Effect": "Allow", "Action": ["s3:GetBucketLocation", "s3:ListBucket"], "Resource": ["arn:aws:s3:::{BUCKET_NAME}", "arn:aws:s3:::{BUCKET_NAME}/*"] } ] } ``` -------------------------------- ### Define Assembly Steps and Create Assembly (Ruby) Source: https://transloadit.com/demos/document-processing/convert-all-pages-of-a-document-into-an-animated-gif Demonstrates using the Ruby SDK to configure an assembly with multiple steps, including thumbnailing and storing results. It prepares the assembly and then creates it, polling for completion. ```ruby # gem install transloadit # $ irb -rubygems # >> require 'transloadit' # => true # transloadit = Transloadit.new([ # :key => "YOUR_TRANSLOADIT_KEY" # ]) # Set Encoding Instructions # _original = transloadit.step(":original", "/upload/handle", {}) # thumbnailed = transloadit.step("thumbnailed", "/document/thumbs", [ # :use => ":original", # :result => true, # :width => 100, # :height => 250, # :delay => 50, # :trim_whitespace => false, # :resize_strategy => "fit", # :background => "#000000", # :format => "gif" # ]) # exported = transloadit.step("exported", "/s3/store", [ # :use => ["thumbnailed", ":original"], # :credentials => "demo_s3_credentials", # :url_prefix => "https://demos.transloadit.com/" # ]) # transloadit.assembly([ # :steps => [_original, thumbnailed, exported] # ]) # Add files to upload # files = [] # files.push("bitcoin.pdf") # Start the Assembly # response = assembly.create! *files # until response.finished? # sleep 1; response.reload! # end # if !response.error? # # handle success # end ``` -------------------------------- ### Define and Execute Transloadit Assembly with JSON and CLI Source: https://transloadit.com/demos/video-encoding/add-text-overlay This example shows how to define a Transloadit assembly using a JSON file and execute it via the command line using the Transloadify CLI. It includes authentication setup via environment variables and defines steps for original file handling, text overlays, and S3 storage. The assembly is then executed with the specified input file and steps file. ```bash # Auth export TRANSLOADIT_KEY="YOUR_TRANSLOADIT_KEY" export TRANSLOADIT_SECRET="YOUR_TRANSLOADIT_SECRET" # Save Encoding Instructions echo '{ "steps": { ":original": { "robot": "/upload/handle" }, "text_overlay_default": { "use": ":original", "robot": "/video/encode", "preset": "empty", "ffmpeg": { "codec:a": "copy", "vf": "drawtext=text='My text overlay':fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2" }, "result": true, "ffmpeg_stack": "v7.0.0" }, "text_overlay_custom": { "use": ":original", "robot": "/video/encode", "preset": "empty", "ffmpeg": { "codec:a": "copy", "vf": "drawtext=font='Times New Roman':text='My text overlay':fontcolor=white:fontsize=24:box=1:boxcolor=black@0.5:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2" }, "result": true, "ffmpeg_stack": "v7.0.0" }, "exported": { "use": ["text_overlay_default", "text_overlay_custom", ":original"], "robot": "/s3/store", "credentials": "demo_s3_credentials", "url_prefix": "https://demos.transloadit.com/" } } }' > ./steps.json # Execute npx transloadit@latest \ --input "surf.mp4" \ --steps "./steps.json" \ --output "./output.example" ``` -------------------------------- ### Swift: Initialize and Use TransloaditKit Source: https://transloadit.com/demos/document-processing/convert-all-pages-of-a-document-into-an-animated-gif This Swift code demonstrates how to initialize the TransloaditKit SDK with credentials and execute an upload. It shows setting up credentials, creating a Transloadit instance, defining upload steps, and handling success or failure responses. It also includes polling for assembly status. ```swift // Install via Swift Package Manager: // dependencies: // .package(url: "https://github.com/transloadit/TransloaditKit", .upToNextMajor(from: "3.0.0")) // Or via CocoaPods: // pod 'Transloadit', '~> 3.0.0' // Auth let credentials = Credentials(key: "YOUR_TRANSLOADIT_KEY", secret: "YOUR_TRANSLOADIT_SECRET") // Init let transloadit = Transloadit(credentials: credentials, session: "URLSession.shared") // Add files to upload let filesToUpload: [URL] = ... // Execute let assembly = transloadit.assembly(steps: [_originalStep, thumbnailedStep, exportedStep], andUpload: filesToUpload) { result in switch result { case .success(let assembly): print("Retrieved (assembly)") case .failure(let error): print("Assembly error (error)") } }.pollAssemblyStatus { result in switch result { case .success(let assemblyStatus): print("Received assemblystatus (assemblyStatus)") case .failure(let error): print("Caught polling error (error)") } } ``` -------------------------------- ### Initialize Transloadit Assembly and Add Steps (Java) Source: https://transloadit.com/demos/video-encoding/concatenate-fade-effect This Java code snippet demonstrates how to initialize the Transloadit SDK and create a new assembly. It shows how to add steps to the assembly, including handling the ':original' file and importing a video from a URL using the '/http/import' robot. It requires the 'com.transloadit.sdk:transloadit' dependency. ```java import com.transloadit.sdk.Assembly; import com.transloadit.sdk.Transloadit; import com.transloadit.sdk.exceptions.LocalOperationException; import com.transloadit.sdk.exceptions.RequestException; import com.transloadit.sdk.response.AssemblyResponse; import java.io.File; import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) { // Initialize the Transloadit client Transloadit transloadit = new Transloadit("YOUR_TRANSLOADIT_KEY", "YOUR_TRANSLOADIT_SECRET"); Assembly assembly = transloadit.newAssembly(); // Set Encoding Instructions Map _originalStepOptions = new HashMap(); assembly.addStep(":original", "/upload/handle", _originalStepOptions); Map preroll_importedStepOptions = new HashMap(); preroll_importedStepOptions.put("result", true); preroll_importedStepOptions.put("url", "https://demos.transloadit.com/inputs/waves10.mp4"); assembly.addStep("preroll_imported", "/http/import", preroll_importedStepOptions); ``` -------------------------------- ### Go SDK: Initialize Transloadit Client and Assembly Source: https://transloadit.com/demos/video-encoding/concatenate-fade-effect This Go code initializes the Transloadit client with authentication credentials and sets up a new assembly. It defines steps for uploading, importing, resizing, and encoding video files using the Transloadit Go SDK. Ensure you replace placeholder credentials with your actual Transloadit API key and secret. ```go options := transloadit.DefaultConfig options.AuthKey = "YOUR_TRANSLOADIT_KEY" options.AuthSecret = "YOUR_TRANSLOADIT_SECRET" client := transloadit.NewClient(options) assembly := transloadit.NewAssembly() assembly.AddStep(":original", map[string]interface{}{ "robot": "/upload/handle", }) assembly.AddStep("preroll_imported", map[string]interface{}{ "robot": "/http/import", "result": true, "url": "https://demos.transloadit.com/inputs/waves10.mp4", }) assembly.AddStep("preroll_resized", map[string]interface{}{ "robot": "/video/encode", "use": "preroll_imported", "result": true, "ffmpeg_stack": "v7.0.0", "preset": "ipad-high", "width": 480, "height": 270, "resize_strategy": "pad", "background": "#00000000", "turbo": false, }) ``` -------------------------------- ### Initialize Uppy with Plugins and Options Source: https://transloadit.com/blog/2018/12/2h-youtube-clone Initializes the Uppy uploader with various plugins and configuration options. This includes setting restrictions, defining meta fields, and integrating with services like Transloadit, Google Drive, and Dropbox. ```javascript uppy.Core({ restrictions: { maxFileSize: 20 * 1024 * 1024, // 20MB maxNumberOfFiles: 20, minNumberOfFiles: 1, allowedFileTypes: ['video/*'] } }) .use(Dashboard, { disablePageScrollWhenModalOpen: false, closeModalOnClickOutside: true, note: 'Maximum size for this demo is 20MB. Please Edit the description of each video before uploading', metaFields: [ { id: 'title', name: 'Title', placeholder: 'Video Title' }, { id: 'license', name: 'License', placeholder: 'Specify license' }, { id: 'caption', name: 'Caption', placeholder: 'Describe what the video is about' }, ], }) .use(Webcam, { target: Dashboard }) .use(Instagram, { target: Dashboard, serverUrl: 'https://api2.transloadit.com/companion', serverPattern: /\.transloadit\.com$/, }) .use(GoogleDrive, { target: Dashboard, serverUrl: 'https://api2.transloadit.com/companion', serverPattern: /\.transloadit\.com$/, }) .use(Dropbox, { target: Dashboard, serverUrl: 'https://api2.transloadit.com/companion', serverPattern: /\.transloadit\.com$/, }) .use(Url, { target: Dashboard, serverUrl: 'https://api2.transloadit.com/companion', serverPattern: /\.transloadit\.com$/, }) .use(Transloadit, { params: { auth: { key: 'YOUR_TRANSLOADIT_AUTH_KEY', }, template_id: 'YOUR_TRANSLOADIT_TEMPLATE_ID', }, waitForEncoding: true, }) ``` -------------------------------- ### Install Firebase Functions Dependencies Source: https://transloadit.com/blog/2018/12/2h-youtube-clone Installs essential libraries for Firebase Functions, including Express.js for API routing, body-parser and cors for request handling, firebase-admin for backend access, and transloadit for media processing. ```bash cd functions npm install --save body-parser cors express firebase-admin transloadit ``` -------------------------------- ### Configure and Start Assembly with Image Processing (Go) Source: https://transloadit.com/demos/image-manipulation/properly-preserve-transparency-across-all-image-types This Go code snippet shows how to initialize the Transloadit client, create a new assembly, and define several processing steps. These steps include filtering images based on MIME type and transparency, resizing them, and finally storing the results in an S3 bucket. It then uploads files and waits for the assembly to complete, printing URLs for the processed files. ```go // go get gopkg.in/transloadit/go-sdk.v1 package main import ( "context" "fmt" "github.com/transloadit/go-sdk" ) func main() { // Create client options := transloadit.DefaultConfig options.AuthKey = "YOUR_TRANSLOADIT_KEY" options.AuthSecret = "YOUR_TRANSLOADIT_SECRET" client := transloadit.NewClient(options) // Initialize new Assembly assembly := transloadit.NewAssembly() // Set Encoding Instructions assembly.AddStep(":original", map[string]interface{}{ "robot": "/upload/handle", }) assembly.AddStep("nontransparent_filtered", map[string]interface{}{ "use": ":original", "robot": "/file/filter", "result": true, "accepts": [['${file.mime}', 'regex', 'image/jpe?g']], "error_on_decline": false, }) assembly.AddStep("maybetransparent_filtered", map[string]interface{}{ "use": ":original", "robot": "/file/filter", "result": true, "declines": [['${file.mime}', 'regex', 'image/jpe?g']], "error_on_decline": false, }) assembly.AddStep("nontransparent_resized", map[string]interface{}{ "use": "nontransparent_filtered", "robot": "/image/resize", "result": true, "resize_strategy": "fit", "width": 400, "height": 300, }) assembly.AddStep("maybetransparent_resized", map[string]interface{}{ "use": "maybetransparent_filtered", "robot": "/image/resize", "result": true, "resize_strategy": "fit", "background": "none", "width": 400, "height": 300, }) assembly.AddStep("exported", map[string]interface{}{ "use": [ "nontransparent_filtered", "maybetransparent_filtered", "nontransparent_resized", "maybetransparent_resized", ":original", ], "robot": "/s3/store", "credentials": "demo_s3_credentials", "url_prefix": "https://demos.transloadit.com/", }) // Add files to upload assembly.AddFile("chameleon.jpg")) assembly.AddFile("fender-png-with-trans.png')) // Start the Assembly info, err := client.StartAssembly(context.Background(), assembly) if err != nil { panic(err) } // All files have now been uploaded and the Assembly has started but no // results are available yet since the conversion has not finished. // WaitForAssembly provides functionality for polling until the Assembly // has ended. info, err = client.WaitForAssembly(context.Background(), info) if err != nil { panic(err) } fmt.Printf("You can check some results at: ") fmt.Printf(" - %s\n", info.Results[":original"][0].SSLURL) fmt.Printf(" - %s\n", info.Results["nontransparent_filtered"][0].SSLURL) fmt.Printf(" - %s\n", info.Results["maybetransparent_filtered"][0].SSLURL) fmt.Printf(" - %s\n", info.Results["nontransparent_resized"][0].SSLURL) fmt.Printf(" - %s\n", info.Results["maybetransparent_resized"][0].SSLURL) fmt.Printf(" - %s\n", info.Results["exported"][0].SSLURL) } ``` -------------------------------- ### Install Firebase CLI Tool (npm) Source: https://transloadit.com/blog/2018/12/2h-youtube-clone This command installs the Firebase Command Line Interface globally on your system using npm. The Firebase CLI is essential for managing Firebase projects, deploying applications, and interacting with various Firebase services from your terminal. ```bash npm install -g firebase-tools ``` -------------------------------- ### Create Upload Options with Convex in Node.js Source: https://transloadit.com/demos/audio-encoding/ffmpeg-fade-in-and-out This Node.js example uses the '@transloadit/convex' library to generate assembly options for Transloadit. It defines audio encoding steps similar to other examples and integrates with a Convex action handler. Requires '@transloadit/convex' and related Convex packages. ```javascript // npm i @transloadit/convex import { makeTransloaditAPI } from '@transloadit/convex' import { components } from './_generated/api' import { action } from './_generated/server' const { createAssemblyOptions } = makeTransloaditAPI(components.transloadit) export const createUpload = action({ args: {}, handler: async (ctx) => createAssemblyOptions(ctx, { steps: { ':original': { robot: '/upload/handle', }, encode_audio: { use: ':original', robot: '/audio/encode', result: true, ffmpeg_stack: 'v7.0.0', preset: 'mp3', ffmpeg: { af: 'afade=t=in:st=0:d=4, afade=t=out:st=13:d=3', to: '16', }, }, exported: { use: ['encode_audio', ':original'], robot: '/s3/store', credentials: 'demo_s3_credentials', url_prefix: 'https://demos.transloadit.com/', }, }, additionalParams: { auth: { ``` -------------------------------- ### Swift: Initialize TransloaditKit for File Uploads Source: https://transloadit.com/demos/video-encoding/concatenate-fade-effect This Swift code snippet shows how to initialize the TransloaditKit SDK for iOS. It includes instructions for installation via Swift Package Manager or CocoaPods. The code demonstrates creating `Credentials` with your Transloadit key and secret, initializing the `Transloadit` client, and preparing an assembly with specified steps and files to upload. It also shows how to handle the assembly result or errors asynchronously. ```swift // Install via Swift Package Manager: // dependencies: [ // .package(url: "https://github.com/transloadit/TransloaditKit", .upToNextMajor(from: "3.0.0")) // ] // Or via CocoaPods: // pod 'Transloadit', '~> 3.0.0' // Auth let credentials = Credentials(key: "YOUR_TRANSLOADIT_KEY", secret: "YOUR_TRANSLOADIT_SECRET") // Init let transloadit = Transloadit(credentials: credentials, session: "URLSession.shared") // Add files to upload let filesToUpload: [URL] = ... // Execute let assembly = transloadit.assembly(steps: [ _originalStep, preroll_importedStep, preroll_resizedStep, original_resizedStep, concatenatedStep, encodeStep, exportedStep, ], andUpload: filesToUpload) { result in switch result { case .success(let assembly): print("Retrieved (assembly)") case .failure(let error): print("Assembly error (error)") } }.pollAssemblyStatus { result in switch result { case .success(let assemblyStatus): print("Received assemblystatus (assemblyStatus)") case .failure(let error): print("Caught polling error (error)") } } ``` -------------------------------- ### Initialize Firebase Project (CLI) Source: https://transloadit.com/blog/2018/12/2h-youtube-clone This sequence of commands first creates a new directory for your API project, navigates into it, and then initializes a new Firebase project within that directory. The `firebase init` command guides you through selecting project features and setting up necessary configuration files. ```bash # Create a directory which will house our API mkdir youtube_clone_api # Move into the API folder cd youtube_clone_api # Initiate Firebase firebase init ```