如何将 pdf 从 iOS 设备文件系统(而不是从项目内)上传到钛工作室中的服务器


如何使用

钛在iOS设备中打开/访问文件系统,以便我获得所有pdf(或任何扩展名)文件的列表并选择文件,获取文件的路径,然后上传。(就像在安卓中一样,我们可以访问文件系统)

这是官方文档的答案

Titanium.Media.openPhotoGallery({
success:function(event) {
/* success callback fired after media retrieved from gallery */
    var xhr = Titanium.Network.createHTTPClient();
    xhr.onload = function(e) {
        Ti.UI.createAlertDialog({
              title:'Success',
              message:'status code ' + this.status
        }).show();
    };
    xhr.open('POST','https://myserver.com/api/uploadAndPost.do');
    xhr.send({
        theImage:event.media,  /* event.media holds blob from gallery */
        username:'foo',
        password:'bar'
      });
}
});

但我认为它只会打开图像.

也请告诉这是否可能。以及如何从桌面在iOS模拟器中添加pdf文件?

我使用钛 sdks 3.4.1

谢谢

您可以使用以下命令读取任何类型的文件:

var file = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory + 'myfile.pdf');
var fileUpload = Titanium.Utils.base64encode(file);

并发送:

xhr.send({media: fileUpload, userame: 'foo', ... });

您可以将文件添加到应用程序的文档目录中,这是在 Mac 上的 iOS 上:

../youruser/Library/Devices/CoreSimulator/Devices/anyGUIDfromDevice/data/.... 

最新更新