Thursday, October 10, 2013

Uploading large content for package backed resources or bundles with the RHQ CLI

Until recently, the only way to create a package backed resource, update its backing content or create a bundle version with the RHQ CLI was to fully load the file in memory as a byte array.

Consequently, as soon as you tried to send something of relatively large size, the CLI crashed with OutOfMemoryError. In practice, with the default CLI max heap size (128MB), that would be about 60 MB.

There is now a way to avoid that and send content or bundles of any size. The ContentManager has been extended to allow fragmented content uploads:


As you can imagine, you'll have to request first the creation of new temporary content handle. Then you'll be able to upload fragments sequentially. For ease of use, a utility method has been added to the ScriptUtil object (bound to 'scriptUtil' ):


So here's how you'll create a package backed resource:


The bundles.js sample script has also been updated in order to upload the bundle file in fragments when creating a bundle version:


These changes have been pushed to the master branch and will be released with RHQ 4.10.

That's it!