Question about unique_prefix for /s3/store robot

Archived from the Transloadit support forum. Originally posted on January 17, 2011; details may be outdated, see our docs for current behavior. Original thread

Per the docs:

${unique_prefix} A unique 33 character prefix you can use to avoid file name collisions. Example: “f2/d3eeeb67479f11f8b091b04f6181ad”

Is the format always 2 characters followed by a slash (“/”) followed by the remaining 30 characters? The reason I ask is because when a file is processed it returns an [ID] in the Results array, which looks like this:

[id] => REDACTED

which seems to be the same as “unique_prefix”, just without the “/” at the 3rd character. I may be storing the ID in my DB, and want to be able to accurately reconstruct the s3 path to the file.

Thanks.

I may be storing the ID in my DB, and want to be able to accurately reconstruct the s3 path to the file.

Yes, the ${unique_prefix} is based on the file id, and we probably won’t change that anytime soon.

But I would recommend you to not build on this assumption. I mean you’ll save a few bytes in your db, but if your url scheme ever changes, this will be a pain to maintain.

--fg

What about passing variables from our form to be used in the path? I have a unique domain key that I would love to use in storing the S3 files so that each of my domains would show up as a different folder under the bucket.

e.g. “path”:“${passed_variable}/${file.urlName}”

Yes, that is exactly what I am trying to do. Is that possible?

You can do that by simply overwriting your template with dynamic parameters.

Assuming you have a template like this:

{
  "steps": {
    "export": {
      "robot": "/s3/store",
      "bucket": "my-bucket",
      "key": "REDACTED",
      "secret": "REDACTED"
    }
  }
}

You can “inject” a dynamic path in this template by embedding the following in your form:

{
  "template_id": "your-template-id",
  "steps": {
    "export": {
      "path": "your-variable/${file.urlName}"
    }
}

Let me know if that works for you / if it makes sense.

--fg

How do I get the variable from the form?

Like this maybe?

<input type="hidden" name="params" value='
    {"auth":{"key":"REDACTED"},
    "template_id":"REDACTED",
    "redirect_url":"http:\/\/localhost\/greyback_razor\/multi.php",
    "variable_path":"something_unique"}' /> 
<input type="file" name="my_file" multiple="multiple"/> 
<input type="submit" value="Upload">

How do I get the variable from the form?

Unfortunately we can’t do it that way. That’s because eventually all of our robots will be realtime, and we may not have received your variable yet when the step is executed.

In my previous comment I was trying to explain that you can “overwrite” the path parameter of your template inside the params field you send to transloadit. Hit me up on skype tomorrow and I can explain this further!

Closing this now after clarifying with Tony via Skype. If there are more questions, please feel free to re-open this ticket!