Create image variety with JS API?


(Jamie Smith) #1

Does anyone know if you can create an image variety with the JS API?

 

I've tried this...

js_api.createAsset({
    "parent_id": <parent_asset_id>,
    "asset_name": "<variety_name>",
    "type_code": "image_variety",
    "link_type": 2,
    "dataCallback": function (data) {
        console.log(data);
    }
});

...but get an error message:

 

error"Exception occured when executing JS API function "createAsset()": Assertion failed: [NULL] "" is not a valid asset ID"

 

I could do it with a Trigger, but it'd be nicer to do in JS.

 

Cheers,

Jamie


(Talk) #2

Are you trying to manually set newly uploaded images as varieties of preexisting images? If so, why?

 

 

I always thought triggers handled this action really, really well - and I'd go for the trigger option personally, even if JS API could do it, if only to save time and ensure consistency.

 

That said, you won't be able to upload an image (or image variety) with this method unless you're posting your file somewhere that can handle its upload. SOAP API can handle file uploads, but it all gets a little complicated - when a Trigger will take 30 seconds to set up.


(Jamie Smith) #3

@jhewitt86: Thanks for responding. That's exactly what I'm trying to do. I need to reduce the size of an uploaded image if it's too big. Creating a variety is one way I could accomplish this.

 

I'd like to do it in JS rather than a Trigger because the rest of the functionality I'm writing is in JS. Also, detecting in JS when a Trigger has done its work will be slightly faffy.


(Anthony) #4

I have JS code that posts an image to an AssetBuilder asset, and a trigger that generates the varieties needed... theres usually a bit of a delay before anything would then try and retrive the image variety to display, but I've certainly never seen a problem with this approach.