Open brospars opened 8 years ago
@brospars Did you manage to get this all working with the file uploading to a server? Could you post some sample code?
Yes I did, with PHP (and node-webkit but I don't think it's what you're loking for). Here's how :
fileReader.readAsDataURL(file, $scope)
.then(function(result) {
$http({
method: 'POST',
url: 'path/to/phpscript.php',
data: result
}).then(function successCallback(response) {
//handle success
}, function errorCallback(response) {
//handle error
});
});
<?php
$filepath = 'path/to/newfile';
//retrieve raw data
$rawData = file_get_contents('php://input');
//get the base64 image from the data
$encodedData = substr($rawData, strpos($rawData, ",")+1);
//decode it
$data = base64_decode($encodedData);
//save it to the new file
file_put_contents($filepath, $data);
You should do a service and add some error handling but you get the idea ;) hope that helps
Hi ! I've been using dyn-form for a while and it's great, it helps me a lot ! So thanks !
One thing I didn't use so far was the
<input type="file"/>
, and I had trouble using it. Your readme file misses maybe some usage example (or I missed it)"callback":"readFile()"
(ng-change) or"attributes": {"on-change":"readFile()"}
(it's the latter)fileReader
injected in your controllerfileReader.readAsDataUrl
in your plugin it'sfileReader.readAsDataURL
(URL full caps ^^)Example for one image file :
Not much but if it can help people (like me) understand better how it works without looking to the source file, I leave it here !