var ft=new FileTransfer()在iOS模拟器中不起作用。CordovaFileTransfer插件问题
我想将我的图像从ios模拟器中的照片库上传到我的amzazon s3存储桶。这段代码在android上运行良好,但拒绝在iOS上运行,我不知道为什么 从图像库中选择照片的代码var ft=new FileTransfer()在iOS模拟器中不起作用。CordovaFileTransfer插件问题,ios,angularjs,cordova,ionic-framework,cordova-plugins,Ios,Angularjs,Cordova,Ionic Framework,Cordova Plugins,我想将我的图像从ios模拟器中的照片库上传到我的amzazon s3存储桶。这段代码在android上运行良好,但拒绝在iOS上运行,我不知道为什么 从图像库中选择照片的代码 $scope.choosePhoto = function(index) { var options = { destinationType : Camera.DestinationType.FILE_URL, sourceType : Camera.PictureSourceType
$scope.choosePhoto = function(index) {
var options = {
destinationType : Camera.DestinationType.FILE_URL,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit : false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
mediaType: Camera.MediaType.PICTURE,
correctOrientation: true
};
// 3
$cordovaCamera.getPicture(options).then(function(imageData) {
// 4
var imagetype;
onImageSuccess(imageData);
function onImageSuccess(fileURI) {
createFileEntry(fileURI);
}
function createFileEntry(fileURI) {
window.resolveLocalFileSystemURL(fileURI, copyFile, fail);
}
// 5
function copyFile(fileEntry) {
var name = fileEntry.fullPath.substr(fileEntry.fullPath.lastIndexOf('/') + 1);
var newName = (new Date()).getTime() + name;
halfthru(fileEntry, newName); //diff
getImageType(fileEntry); //diff
}
function getImageType(fileEntry) { //diff
var typeImage;
$scope.$evalAsync(function() {
fileEntry.file(function(file){
typeImage= file.type;
$scope.imagelist = typeImage;
imagetype = typeImage;
}, function(e){
});
})
}
function halfthru(fileEntry, newName) {
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(fileSystem2) {
fileEntry.copyTo(
fileSystem2,
newName,
onCopySuccess,
fail
);
}, fail);
}
// 6
function onCopySuccess(entry) {
$scope.activeSlide = index;
$scope.modal1.show();
$scope.$evalAsync($scope.images.push({file: entry.nativeURL, type: $scope.imagelist}));
imagesModalCount = $scope.images.length;
attachedImageCount = $scope.imagesAttached.length;
$scope.$on('$destroy', function() {
$scope.modal1.remove();
});
}
function fail(error) {
}
}, function(err) {
});
}
要上传到amazon的代码
$scope.uploadImage = function(imageURI, fileName) {
var deferred = $q.defer();
createCase.getAws().then(function(awsDetails) {
var policy = awsDetails.policy;
var signature = awsDetails.signature;
var key = awsDetails.key;
var datenow = awsDetails.datenow;
var s3URI = encodeURI("https://partners-mobile-app.s3.amazonaws.com/"),
awsKey = key,
policyBase64 = policy,
acl = "public-read";
var ft = new FileTransfer();
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = fileName;
options.mimeType = "image/jpeg";
options.chunkedMode = false;
options.headers = {
Connection: "close"
};
options.params = {
"key": fileName,
"AWSAccessKeyId": key,
"acl": acl,
"policy": policyBase64,
"signature": signature,
"Content-Type": "image/jpeg"
};
var f = ft.upload(imageURI, s3URI,
function (e) {
console.log("uploadimage: "+ imageURI)
console.log("uploads3uri: "+ s3URI)
console.log("im in upload now")
$scope.finalimagelist.push(s3URI+fileName);
if($scope.finalimagelist.length === $scope.images.length){
console.log("OK SER GO")
deferred.resolve($scope.finalimagelist);
}
},
function (e) {
deferred.reject(e);
},
options);
}
所以基本上,我从图片库中选择图片,然后上传到亚马逊。一切看起来都不错,但它就是不上传图片,我不知道为什么
我正在使用AngularJS和插件cordova插件文件传输
我的信息列表
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
NSAppTransportSecurity
NSAllowsArbitraryLoads
请看一下这个。在我看来,这整件事似乎是iOS 9上ATS/Apple传输安全的一个问题
这将是它的解决方案:
请看一下这个。在我看来,这整件事似乎是iOS 9上ATS/Apple传输安全的一个问题 这将是它的解决方案:
我已经在plist文件中添加了NSTransportSecurity。因此,我认为问题不在于分享你的
info.plist
以及你的白名单设置NSAppTransportSecurity NSAllowsArbitraryLoads我认为我没有每次在xcode上运行cordova插件白名单时白名单BCO的设置,它一直告诉我它已被弃用,我已经在我的plist文件中添加了NSTransportSecurity。因此,我不认为这个问题与您的info.plist
有关。此外,您的白名单设置NSAppTransportSecurity NSAllowsArbitraryLoads我不认为每次在xcode上运行cordova插件白名单时,我都有白名单BCO的设置,它不断告诉我它已被弃用