Hi! In my company, we had two projects using enonic that we needed the creation of a media content using a url instead of a file from multipart-form, for example. If there’s any way I could create this media, please help me. I’ve tried in a controller, do a request with httpClientLib, create a stream with ioLib using the response and then creating a media object. This doesn’t worked. Would be nice for next versions, implement a function like content.createMedia(), but content.createMediaFromUrl() or something like this.
We are planning to improve stream (binary) support in http-client lib, by adding a bodyStream property on the result of the request function. Then you will be able to pass the result to createMedia data parameter.
It will work something like this:
var response = httpClientLib.request({
url: 'http://host/image.png',
method: 'GET'
});
var responseStream = response.bodyStream; // this field is currently missing
var mediaResult = contentLib.createMedia({
name: 'myImage',
parentPath: '/some/path',
mimeType: 'image/png',
data: responseStream
});
Then it becomes simple to create your own createMediaFromUrl() function.
Hopefully this will be a part of the next 6.6 version.