Sto lavorando a un'app di chat ionica in cui l'utente può caricare una foto come parte del messaggio. Sto cercando un modo per caricare l'immagine sul mio server webhost in modo che possa recuperarla in un secondo momento tramite un URL.Caricamento di immagini app ioniche dalla fotocamera/libreria fotografica
Il problema è che non riesco a farlo caricare sul mio server web.
sto usando questi due plugin:
- org.apache.cordova.file trasferimento
- Cordova-plugin-fotocamera
Quando eseguo l'applicazione in simulatore di Xcode e selezionare una foto dalla libreria del dispositivo, la console mi dà i seguenti messaggi:
File Transfer Finished with response code 200
void SendDelegateMessage(NSInvocation *): delegate (webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode>
SUCCESS: ""
Questo è il codice che attualmente uso:
app.controller('HomeController', function($rootScope, $scope, $cordovaCamera, $ionicActionSheet, $cordovaFileTransfer){ ...
// open PhotoLibrary
$scope.openPhotoLibrary = function() {
var options = {
quality: 100,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function(imageData) {
//console.log(imageData);
//console.log(options);
var url = "http://mydomein.com/upload.php";
//target path may be local or url
var targetPath = imageData;
var filename = targetPath.split("/").pop();
var options = {
fileKey: "file",
fileName: filename,
chunkedMode: false,
mimeType: "image/jpg"
};
$cordovaFileTransfer.upload(url, targetPath, options).then(function(result) {
console.log("SUCCESS: " + JSON.stringify(result.response));
alert("success");
alert(JSON.stringify(result.response));
}, function(err) {
console.log("ERROR: " + JSON.stringify(err));
alert(JSON.stringify(err));
}, function (progress) {
// constant progress updates
$timeout(function() {
$scope.downloadProgress = (progress.loaded/progress.total) * 100;
})
});
}, function(err) {
// error
console.log(err);
});
}
Questo è il mio file upload.php:
<?php
// move_uploaded_file($_FILES["file"]["tmp_name"], $cwd . '/files/images/');
move_uploaded_file($_FILES["file"]["tmp_name"], "/files/images");
?>
Che dire se usi un altro server come Node.js e Express.js? –