如何通过没有base64编码的Worklight服务器发送图像? [英] How to send images through Worklight server without base64 encoding?

查看:80
本文介绍了如何通过没有base64编码的Worklight服务器发送图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出如何使用Worklight适配器将图像发送到我的后端服务器。
我知道我可以使用Base64编码通过Worklight适配器发送它们,但这意味着服务器之间的流量增加了大约30%,并且有一些不希望的处理开销。

I`m trying to find out how to send images to my back-end server using Worklight adapters. I know that I can send them through Worklight adapters using Base64 encoding but this implies in around 30% more traffic between the servers and some undesired processing overhead.

现在我正在使用Phonegap FileTransfer库,如下所示,但是这会在客户端和后端服务器之间创建一个直接连接,而不是通过Worklight服务器。

For now I`m using the Phonegap FileTransfer library as I show below, but this creates a directly connection between the client and the back-end server not going through Worklight server as I want.

var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";

var headers = {"Content-Type": "image/jpeg"};
options.headers = headers;

var ft = new FileTransfer();
ft.upload(imageURI, encodeURI(host + "/images"), imageUploadSuccess, imageUploadFail, options);

function imageUploadSuccess(r) {
    WL.Logger.debug("Submit success! HTTP Status Code = " + r.responseCode);
    WL.Logger.debug("Response = " + r.response);
    WL.Logger.debug("Bytes sent = " + r.bytesSent);
    $.mobile.changePage('#SuccessPage');
}
function imageUploadFail(error) {
    WL.Logger.debug("submit error! source = " + error.source);
    WL.Logger.debug("target = " + error.target);
    $.mobile.changePage('#FailPage');
}

我有办法做到这一点吗?

Is there a way that I can do that?

提前谢谢。

- 编辑 -

另一个发生的问题是,当我的后端服务器收到文件时,它似乎已损坏,无法作为图像重新加入。

Another problem that occurs is that when my backend server receives the file, it seems corrupted and cannot be readed as an image.

推荐答案

这次,Worklight适配器不支持以二进制形式发送数据。

At this time, Worklight adapters do not support sending data in binary form.

这意味着目前您唯一的选择是您不喜欢的选项,即base64编码图像文件并将结果字符串存储在数据库中,当您需要使用它时,对它进行base64解码。

This means that currently your only option is the one you do not like, which is to base64 encode the image file and store the resulting string in the database and when you need to use it, to base64 decode it.

这篇关于如何通过没有base64编码的Worklight服务器发送图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆