@sioessi wrote:
I'm trying to upload an image from my mobile device does not work. Try to upload from an input type file and run without any problem, but not selecting images from the library or taking pictures with the camera up images.
The code then receives 200 a response from my server I also get good response received and that something could be processed. However, the picture that is saved is black, you can not open the file.
$scope.uploadPicture = function() { var img = document.getElementById('imagen_usuario'); var imageURI = img.src; // Verify server has been entered server = UrlUpdateFile.url + "/" + imageURI.substr(imageURI.lastIndexOf('/') + 1); if (server) { // Specify transfer options var options = new FileUploadOptions(); options.fileKey = "file"; options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1); options.mimeType = "image/jpeg"; options.chunkedMode = false; // Transfer picture to server var ft = new FileTransfer(); ft.upload(imageURI, server, function(r) { console.log(r); }, function(error) { console.log(error); }, options); } }
However, with this code works.
$scope.uploadPicture = function() { fileData = document.getElementById("file").files[0]; var data = new FormData(); console.log(fileData); $.ajax({ url: UrlUpdateFile.url + "/" + fileData.name, type: 'POST', data: fileData, cache: false, dataType: 'json', processData: false, // Don't process the files contentType: "application/octet-stream", // Set content type to false as jQuery // will tell the server its a query string request success: function(data) { alert('successful..'); }, error: function(data) { alert('Some error Occurred!'); } }); }
That as a comment is a file input type.
Config camera
$scope.takePicture = function() { var options = { quality: 50, targetWidth: 512, targetHeight: 512, destinationType: Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType.CAMERA, encodingType: Camera.EncodingType.JPEG, correctOrientation: true, popoverOptions: CameraPopoverOptions, saveToPhotoAlbum: false, }; $cordovaCamera.getPicture(options).then(function(imageData) { $scope.photo = imageData; var img = document.getElementById('imagen_usuario'); img.src = imageData; }, function(err) { // An error occured. Show a message to the user }); }
Posts: 1
Participants: 1