CollectionFS - Renaming files dynamically?


#1

Hey, folks. I’m attempting to figure out a way to dynamically set the name on files being uploaded to Amazon S3 via CollectionFS (cfs:s3).

The following code is sort of a starting point, I just don’t know where to go from here:

var modStore = new FS.Store.S3("modFiles", {
    accessKeyId: "--key--",
    secretAccessKey: "--key--",
    bucket: "meteor-intrepid",
    folder: "mods",
    beforeWrite: function(fileObj) {
        return {
            name: "RenameTest"
        }
    }
});

What I can’t figure out is how I’m going to get form data into beforeWrite. The following bit of code is the form that’s being used to store files in this collection:

{{#autoForm collection="ModUploads" id="uploadFileForm" type="insert"}}
    <fieldset>
        <section class="centered">
            {{> afQuickField name="file" label=false}}
        </section>
        {{#if noMods}}
            No Mods!
        {{ else }}
            <section class="form-group">
                <label for="mod">Mod:</label>
                <select class="form-control" data-schema-key="mod" id="mod" name="mod">
                {{#each mods}}
                    <option value="{{ _id }}">{{ name }}</option>
                {{/each}}
                </select>
            </section>
        {{/if}}
        {{> afQuickField name="version" }}
        <button type="submit" class="btn btn-default btn-block">Upload File</button>
    </fieldset>
{{/autoForm}}

What I would like to do is pull the text of the selected ‘mod’ option, as well as grab the value of the “version” field, and use those to build the filename of the object being stored, but I have no idea how to pass that information where it needs to go. Any help would be greatly appreciated, I know there’s probably got to be some way to do what I’m wanting to do, I just…can’t figure it out for the life of me.