从 mobilefirst http 适配器获取 jpg 图像
get an jpg image from a mobilefirst http adapter
我在 mobilefirst 适配器 (6.3) 中工作,它需要从内部网络文件系统中的 url 传递图像(例如:http://www.up.edu.pe/RED_Compartir/facebook.png),但我无法获取数据正确地,img 数据不在文本变量中:
这是我的服务器端代码:
function getImage(id){
var input = {
method : 'get',
returnedContentType : 'plain',
path : '/someUrl/someUrl2/'+id+'.jpg'
};
return {
out: Base64.encode(WL.Server.invokeHttp(input).text)
};
}
这是我处理图像的客户端代码:
function getImageFrom() {
execMobileFirstAdapter("adapterName", "method", ["parameter"]).then(function (data){
WL.Logger.debug("OK")
var imageBase = data.invocationResult.out;
document.getElementById('imageServer').setAttribute( 'src', 'data:image/jpeg;base64,'+ imageBase );
}).fail(function(data){
WL.Logger.debug("error");
})
}
有没有办法从 MobileFirst 适配器的 jpg 图像中 return base64?
并且工作完美,但我只需要在服务器中使用 JavaScript 来执行此操作。这可能吗?
Is there a way to return the base64 from a jpg image from a
mobilefirst adapter?
I've used this example:
https://www.ibm.com/developerworks/community/blogs/mobileblog/entry/ibm_worklight_adapter_accessing_an_image?lang=en
and Works perfectly but i need to do this only with JavaScript in the
server. is this possible?
事实上,最简单的方法是按照您提供的文章中示例的方式实现它。
唯一的其他方法是找到一个 JavaScript 进行 base64 编码的库,并尝试将此库添加到适配器中,然后使用它。
请注意,JavaScript 适配器不支持向适配器添加额外的文件,因此这意味着您需要获取您将找到的任何库的完整实现并将其放入您的适配器代码中。不太好。也不保证它会起作用。
此外,您是从 Cordova 插件内部调用适配器吗?那很奇怪。为什么?为什么不直接使用 WL.Client.invokeProcedure API... 就像文章中那样...
我在 mobilefirst 适配器 (6.3) 中工作,它需要从内部网络文件系统中的 url 传递图像(例如:http://www.up.edu.pe/RED_Compartir/facebook.png),但我无法获取数据正确地,img 数据不在文本变量中: 这是我的服务器端代码:
function getImage(id){
var input = {
method : 'get',
returnedContentType : 'plain',
path : '/someUrl/someUrl2/'+id+'.jpg'
};
return {
out: Base64.encode(WL.Server.invokeHttp(input).text)
};
}
这是我处理图像的客户端代码:
function getImageFrom() {
execMobileFirstAdapter("adapterName", "method", ["parameter"]).then(function (data){
WL.Logger.debug("OK")
var imageBase = data.invocationResult.out;
document.getElementById('imageServer').setAttribute( 'src', 'data:image/jpeg;base64,'+ imageBase );
}).fail(function(data){
WL.Logger.debug("error");
})
}
有没有办法从 MobileFirst 适配器的 jpg 图像中 return base64?
并且工作完美,但我只需要在服务器中使用 JavaScript 来执行此操作。这可能吗?
Is there a way to return the base64 from a jpg image from a mobilefirst adapter?
I've used this example: https://www.ibm.com/developerworks/community/blogs/mobileblog/entry/ibm_worklight_adapter_accessing_an_image?lang=en
and Works perfectly but i need to do this only with JavaScript in the server. is this possible?
事实上,最简单的方法是按照您提供的文章中示例的方式实现它。
唯一的其他方法是找到一个 JavaScript 进行 base64 编码的库,并尝试将此库添加到适配器中,然后使用它。
请注意,JavaScript 适配器不支持向适配器添加额外的文件,因此这意味着您需要获取您将找到的任何库的完整实现并将其放入您的适配器代码中。不太好。也不保证它会起作用。
此外,您是从 Cordova 插件内部调用适配器吗?那很奇怪。为什么?为什么不直接使用 WL.Client.invokeProcedure API... 就像文章中那样...