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.
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?
Thank you in advance.
-- Edit --
Another problem that occurs is that when my backend server receives the file, it seems corrupted and cannot be readed as an image.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…