Importing media from url


#1

Continuing the discussion from Import media from url:

Hi, The httpClientLib doesn’t return body or bodyStream if the contentType is not text. So how do I get stream for image, is there something that I need to send as part of the request?


(Documentation from httpClientLib)


#2

Hi, I just tested the code from the link above to fetch the image and save it as content. Everything worked perfectly fine without any extra parameters. See the code below. Can you post yours?

var httpClientLib = require('/lib/http-client');
var response = httpClientLib.request({
    url: 'https://enonic.com/_/image/ce090bca-c09d-414c-ab57-0721b771e548:3f844b5a7cde4161dac57cc5e80633eccd1018d7/full/pwa.png',
    method: 'GET'
});

var responseStream = response.bodyStream;

var mediaResult = contentLib.createMedia({
    name: 'myImage',
    parentPath: '/',
    mimeType: 'image/png',
    data: responseStream
});

#3

It is working. I had referred the wrong http-Client. Thank you


#4