【发布时间】:2017-05-16 17:31:31
【问题描述】:
我正在尝试使用 Cordova FileTransfer 插件从我的 SAPUI5 应用程序将图像上传到 SAP Http Content Server。
到目前为止,当我上传时,它返回成功代码(200)和以下消息:
Component img1 in Document 0000000018 updated
插件还会以bytesent的成功代码作为响应,这与图像的大小相同,所以我假设图像已上传。
但是当我使用get 函数来检索我的图像时,什么都没有。身体是空的。当我使用网络浏览器时,它会让我下载一个空的ContentServer.dll 文件,而当我使用 Postman 时,响应正文是空的。 AFAIK,在这样的成功案例中,主体就是图像,而对于 Postman,它在响应的主体中给出图像的二进制形式。
对于我的代码,我使用 Cordova Camera(我尝试了 Media Capture 但同样的问题)插件来拍摄如下照片:
takePhoto: function() {
navigator.camera.getPicture(onCapturePhoto, onFail, {
quality: 100,
destinationType: destinationType.FILE_URI
});
}
拍照成功后调用onCapturePhoto函数:
function onCapturePhoto(fileURI) {
var options = new FileUploadOptions();
options.fileKey = "file";
options.httpMethod = "PUT";
** This line below solved my first problem but still cannot solve the
original problem as my Update1 mentioned**
options.chunkedMode = false;
options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg";
options.params = {}; // if we need to send parameters to the server request
var win = function(r) {
console.log(r);
console.log(fileURI);
};
var fail = function(error) {
console.log(error);
alert('Ups. Something wrong happens!');
};
var ft = new FileTransfer();
var url = "http://serverIP:1090/ContentServer/ContentServer.dll?update&pVersion=0046&contRep=Z1&docId=0000000018&compId=img1";
ft.upload(fileURI, url, win, fail, options);
}
我想不知何故数据没有传输到服务器,这就是为什么正文总是空的。但我很确定语法是正确的,至少不会给出任何错误。因此,我完全糊涂了。请问有什么建议吗?
Update1: 到目前为止,我发现了问题:是 options.chunkedMode 给出了空响应体。现在我可以看到我的响应正文。但问题是我的身体没有呈现为图像,而是ContentServer.dll。我想我的上传代码对此负责。不知何故,数据在上传时没有正确的图像格式。有什么建议吗?
【问题讨论】:
标签: cordova cordova-plugins sapui5