我正在研究离子,我基本上有一个带有heroku的REST api,无法上传图片,我正在尝试上传使用cordova文件传输插件和HTTP发布请求 我正在使用ionicview在手机上测试我的应用程序 我的api托管在heroku上,可以在此链接https://peaceful-refuge-78844.herokuapp.com/中找到(静态,上传后添加斜杠后的一个选项) 它每次都返回失败的上传
我的控制器:
$scope.testConnection = function()
{
$http.get('https://peaceful-refuge-78844.herokuapp.com/').then(function(result){
$scope.serverConnection = "Connection OK";
},
function(err){
$scope.serverConnection = "Connection fail";
});
}
$scope.choosePhoto = function() {
//Gallery
var options = {
quality: 80,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 500,
targetHeight: 700,
correctOrientation: true,
saveToPhotoAlbum: true
};
$cordovaCamera.getPicture(options).then(function(photo){
$rootScope.imgURI = photo;
$scope.lastPhoto = photo;
})
$scope.uploadPhoto = function()
{
var options = new FileUploadOptions()
options.fileKey = "image";
$cordovaFileTransfer.upload('https://peaceful-refuge-78844.herokuapp.com//upload', $scope.lastPhoto, options).then(function(result) {
console.log("File upload complete");
console.log(result);
$scope.url = result;
$scope.uploadResults = "Upload completed successfully"
}, function(err) {
console.log("File upload error");
console.log(err);
$scope.uploadResults = "Upload failed"
}, function (progress) {
// constant progress updates
console.log(progress);
});
}