【问题标题】:Titanium 5.1.1.GA SDK image file not upload in iosTitanium 5.1.1.GA SDK 图像文件未在 ios 中上传
【发布时间】:2016-01-20 06:36:39
【问题描述】:

这是我用于将图像上传到服务器的 HTTPClient 代码。这同样适用于 3.5.0.GA SDK 和 4.1.0.GA SDK,但不适用于新的 SDK 5.1.1.GA 和 5.1.2.GA。

var filename = "sample.png";
//Pointer to the file to be uploaded.
var uploadingFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, filename);

Ti.API.info('uploadingFile ' + uploadingFile.exists());
//We are creating a new xhr instead of calling the existing one because we dont want timeout when uploading data.
var xhr = Titanium.Network.createHTTPClient({
    validatesSecureCertificate : false,
    enableKeepAlive : true,
    onload : function() {
        uploadingFile = null;
        Ti.API.info('Success '+tthis.responseText);         
    },
    onerror : function(data) {
        uploadingFile = null;
        Ti.API.info('this.status '+this.status);
    }
});

xhr.onsendstream = function(e) {
    var uploadTime = new Date();
    Ti.API.info('UPLOADING PROGRESS: ' + progress + ' ' + uploadTime.getHours() + ":" + uploadTime.getMinutes() + ":" + uploadTime.getSeconds());
};

xhr.open('POST', httpClient.getUserDomainInfo(config.URLs.imageupload, tenant));
xhr.send({
    file : uploadingFile.read(),
    claimId : claimID,
    filename : filename,
    description : ''
});

错误状态为 500 Internal Server Error。

是 SDK 中的问题还是我需要在代码中更改的任何内容。

请帮帮我。

【问题讨论】:

  • 500 错误表示您的服务器当时正忙或没有响应。请检查您的网址是否正常。
  • 您的服务器上传脚本也可能有错误
  • 相同的 URL 和相同的代码适用于 3.5.0.GA SDK 和 4.1.0.GA SDK。所以我的假设是服务器上传脚本很好。刚刚在 4.1.0GA 中尝试过它工作。我再次尝试在 5.1.1GA 中它不起作用。
  • 我遇到了同样的问题。仍在研究解决方案。

标签: ios appcelerator titanium-mobile appcelerator-titanium


【解决方案1】:

以下代码演示文件上传。根据你的代码修改。

f1 = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,<image name>);
i1 = f1.read();
xhr = Titanium.Network.createHTTPClient();
xhr.open('POST','<url to call>', false); // false makes it synchronous
xhr.onload = function() { handleAfterSentRouting(this.responseText);   };
xhr.send({media1: i1}); // media1 is the field the file information is in when you upload

谢谢。

【讨论】:

    【解决方案2】:

    几周后我遇到了同样的问题,解决方案非常简单,您只需要在服务器上创建另一个 Web 服务页面,仅用于文件上传而不传递任何其他文本参数,在您的情况下,编辑您的 xhr.send 参数以仅包含你的文件如下:

    xhr.send({
        file : uploadingFile
    }); 
    

    所以为你的其他变量创建另一个与另一个 Web 服务器页面相关的 xhr 函数:

    claimId : claimID,
    filename : filename,
    description : ''
    

    它有效;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      相关资源
      最近更新 更多