Automatically reject virus-infected files with an error

The /file/virusscan Robot allows you to reject files in which we detect malware and display an error to the user. Optionally, you can also skip processing these files without an error.

To run this demo, upload a file that contains malware.

Warning It seems your browser does not send the referer, which we need to stop people from (ab)using our demos in other websites. If you want to use the demos, please allow your browser to send its referer to us. Adding us to the whitelist of blockers usually helps.

This demo uses:

  • Our /file/virusscan Robot, which rejects millions of trojans, viruses, malware & other malicious threats before they reach your platform
  • Our /s3/store Robot, which exports encoding results to Amazon S3


If you want Transloadit to handle uploads for you, here is some example HTML and JavaScript that can be integrated directly into your website.

We have a great new JavaScript uploader in the works called Uppy and you are welcome to give that a shot, but for now, the following example uses our jQuery SDK and it is still the recommended way to integrate Transloadit into web browsers.

<html>
<head><title>Some demo title</title></head>
<body>
<form action="/uploads" enctype="multipart/form-data" method="POST">
  <input type="file" name="my_file" multiple="multiple" />
</form>

<script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="//assets.transloadit.com/js/jquery.transloadit2-v3-latest.js"></script>
<script type="text/javascript">
$(function() {
  $("form").transloadit({
    "wait": true,
    "triggerUploadOnFileSelection": true,
    "params": {
      "auth": {
        // Secure via: https://transloadit.com/docs/api-docs/#authentication
        "key": "YOUR_TRANSLOADIT_AUTH_KEY",
      },
      "steps": {
        "safe": {
          "use": ":original",
          "robot": "/file/virusscan",
          "error_on_decline": true
        },
        "store": {
          "robot": "/s3/store",
          "use": "safe",
          "key": "YOUR_AWS_KEY",
          "secret": "YOUR_AWS_SECRET",
          "bucket": "YOUR_S3_BUCKET"
        }
      }
    }
  });
});
</script>
</body>
</html>

So many ways to integrate

Transloadit's versatility not only shines through in our diverse encoding features, but also in the ways that you can integrate with those. Would you like to handle your own file uploads? Or do you have a big library of files ready to be encoded? You leverage Transloadit's highly scalable encoding platform by letting us import from your source or post files directly from your server using a backend language. We have kits available for most platforms.

If there's no kit available for your platform, you can integrate with our REST API.

Perhaps you want Transloadit to also handle uploads? In this case take a look at our HTML integrations.

Notifying your server

Transloadit will then accept the upload on behalf of your site, process all the files according to your Assembly Instructions and export to your storage platform of choice. Your visitor will now in reality be uploading links to the Encoding Results (example) to your website's /uploads URL.

This takes the pressure off your platform, and ensures the user will have a smooth experience.

Typically, it is advisable to save a record of the result in your database, so you will need to inspect the transloadit POST payload that was sent to your /uploads, or Notification URL. In PHP, that would look like this:

print_r(json_decode($_POST['transloadit'], true));

Here is an example of our PHP SDK.

// Install "transloadit/php-sdk" via Composer (https://getcomposer.org)
use transloadit\Transloadit;
$transloadit = new Transloadit(array(
  "key"    => "YOUR_TRANSLOADIT_AUTH_KEY",
  "secret" => "YOUR_TRANSLOADIT_AUTH_SECRET",
));

$response = $transloadit->createAssembly(array(
  "files" => array(
    "./lolcat.jpg",
  ),
  "params" => array(
    "steps" => json_decode({
      "safe": {
        "use": ":original",
        "robot": "/file/virusscan",
        "error_on_decline": true
      },
      "store": {
        "robot": "/s3/store",
        "use": "safe",
        "key": "YOUR_AWS_KEY",
        "secret": "YOUR_AWS_SECRET",
        "bucket": "YOUR_S3_BUCKET"
      }
    }, true),
  ),
));

This demo uses :original, which indicates a user upload that was received by Transloadit. So, for this SDK, you will likely want to add one of our import Robots and use their downloads instead.

Here is an example of our Ruby SDK.

# gem install transloadit
transloadit = Transloadit.new(
  :key    => "YOUR_TRANSLOADIT_AUTH_KEY",
  :secret => "YOUR_TRANSLOADIT_AUTH_SECRET"
)

safe = transloadit.step "safe", "/file/virusscan",
  :use => ":original",
  :error_on_decline => true
)
store = transloadit.step "store", "/s3/store",
  :use => "safe",
  :key => "YOUR_AWS_KEY",
  :secret => "YOUR_AWS_SECRET",
  :bucket => "YOUR_S3_BUCKET"
)

assembly = transloadit.assembly(
  :steps => [ safe, store ]
)

response = assembly.submit! open("./lolcat.jpg")
until response.finished?
  sleep 1; response.reload!
end

if !response.error?
  # handle success
end

This demo uses :original, which indicates a user upload that was received by Transloadit. So, for this SDK, you will likely want to add one of our import Robots and use their downloads instead.

Here is an example of our Node.js SDK.

// npm install transloadit --save
const TransloaditClient = require("transloadit")

const transloadit = new TransloaditClient({
  authKey    : "YOUR_TRANSLOADIT_AUTH_KEY",
  authSecret : "YOUR_TRANSLOADIT_AUTH_SECRET"
})

transloadit.addFile("myimage", "./lolcat.jpg");

const options = {
  params: {
    steps: {
      "safe": {
        "use": ":original",
        "robot": "/file/virusscan",
        "error_on_decline": true
      },
      "store": {
        "robot": "/s3/store",
        "use": "safe",
        "key": "YOUR_AWS_KEY",
        "secret": "YOUR_AWS_SECRET",
        "bucket": "YOUR_S3_BUCKET"
      }
    }
  }
}

transloadit.createAssembly(options, (err, result) => {
  if (err) {
    throw err
  }

  console.log({result})
})

This demo uses :original, which indicates a user upload that was received by Transloadit. So, for this SDK, you will likely want to add one of our import Robots and use their downloads instead.

Here is an example of our Go SDK.

// go get github.com/transloadit/go-sdk
options := transloadit.DefaultConfig
options.AuthKey = "YOUR_TRANSLOADIT_AUTH_KEY"
options.AuthSecret = "YOUR_TRANSLOADIT_AUTH_SECRET"
client, err := transloadit.NewClient(options)
if err != nil {
  panic(err)
}

assembly := client.CreateAssembly()
assembly.AddFile("myimage", "./lolcat.jpg")

assembly.AddStep("safe", map[string]interface{}{
  "use": ":original",
  "robot": "/file/virusscan",
  "error_on_decline": true
})
assembly.AddStep("store", map[string]interface{}{
  "robot": "/s3/store",
  "use": "safe",
  "key": "YOUR_AWS_KEY",
  "secret": "YOUR_AWS_SECRET",
  "bucket": "YOUR_S3_BUCKET"
})

info, err := assembly.Upload()
if err != nil {
  panic(err)
}

This demo uses :original, which indicates a user upload that was received by Transloadit. So, for this SDK, you will likely want to add one of our import Robots and use their downloads instead.

Instead of sending encoding instructions directly to Transloadit, you can also save them in a secured way as a Template. You can then refer to the template_id in your requests, making sure that secrets and instructions no longer have to be transmitted, which might be a security risk in many cases.

Here is the 'raw' Template, in case you would like to save these instructions safely in your account.

{
"steps": {
    "safe": {
      "use": ":original",
      "robot": "/file/virusscan",
      "error_on_decline": true
    },
    "store": {
      "robot": "/s3/store",
      "use": "safe",
      "key": "YOUR_AWS_KEY",
      "secret": "YOUR_AWS_SECRET",
      "bucket": "YOUR_S3_BUCKET"
    }
  }
}

Try it out

Maximum size for all demos is 100MB.

Transloadit is a service for companies with developers. Visitors are welcome to do one-off media conversions but unfortunately we cannot provide support for that, sorry!