I added the plugin by using the link at cli.
Plugin: phonegap local plugin add org.apache.cordova.device
Plugin-Link: https://github.com/hazemhagrass/phonegap-base64
Now I did copy the code in my controller, but it does not work.
Code:
//filePath is the absolute path to the file(/mnt/sdcard/...)
window.plugins.Base64.encodeFile(filePath, function(base64){
console.log('file base64 encoding: ' + base64);
});
My question is, how do I activate the plugin? Like using for example "$cordovaCamera". Maybe somebody can show me a correct controller example. Thanks for your help.
Christoph, The base64 converting is very simple with this plugin , we just need to call this function and pass the file path to that function and it will retun the full base64 string :
here is a simple example :
// Loop through acquired images
window.plugins.Base64.encodeFile(filePath, function(base64){
alert("Base64 image : "+base64);
var base64Data = base64;
//Use this base64 where you wants
});
I hope it will help ypu to convert file to base64 .
have a happy code day
Related
I´m working with files in my application, I´m taking this article as example https://docs.flutter.dev/cookbook/persistence/reading-writing-files, I can read and write the file succesfully, my estructure is the next
{
'products' : {my_items...},
'data_customer' : {info_customer...}
}
But my problem is, It´s possible update the content from 'data_customer', preserving 'products' information?
I tried use the FileMode.writeOnlyAppend, but this only append the info in the end of file, for example
{
'products' : {my_items...},
'data_customer' : {info_customer...}
'data_customer' : {new_info_customer...}
}
I just want to update the information. Thanks in advance
Read the file as string and use json.decode() method to convert it as Map<Sting, dynamic> then change the data and rewrite to the file after decoding it to JSON using json.encode() method.
I upload my images like this:
CloudinaryResponse response = await this.url.uploadImage(filePath,
filename: "background",
folder: "alquileres/$userId/$portfolioId/$investmentId");
The image names are "background_longID". I'd like to overwrite all the images.
I've found an old issue in Github but doesn't provide too much info (https://github.com/cloudinary/cloudinary_ios/issues/87)
You can find details about the upload and various flags for upload on the documentation page at https://cloudinary.com/documentation/image_upload_api_reference#upload_method.
If the primary concern is that you don't want Cloudinary to add the _longId parameter to the file name, you can set the flag unique_filename=false during the upload.
Another flag that you should consider is overwrite. By default, this flag is set to false. So when you re-upload, the old image is not replaced. You could set the flag overwrite=true as well to ensure that the new image is uploaded correctly.
Cloudinary doesn't support integration with flutter. there are some third parties that you can use for example here: https://gist.github.com/Wizpna/eab058e15cc1533bdb73bf764078f642
If you would like to upload images to Cloudinary, our best practice is to add an upload widget. You can read more about it here:
https://cloudinary.com/documentation/upload_widget
For someone who might be having the same issue, here is what i did
CloudinaryClient client = new CloudinaryClient(<API_KEY>, <API SECRET>, <CLOUD NAME>);
await client.uploadImage( file.path, filename: <NAME_FOR_PHOTO>, folder: <FOLDER_NAME(OPTIONAL)>)
.then((result){
print("CLOUDINARY:: ${result.secure_url}==> result");
})
.catchError((error) => print("ERROR_CLOUDINARY:: $error"));
You can use this package https://pub.dev/packages/cloudinary_public which does not require your API_KEY or API_SECRET
I'm getting json data from a wordpress website. Some of the content I fetch can have html codes like ’ or … and I want to convert this to normal caracter like ' or ...
I can't seem to understand what function to use from the dart API to do this.
I've been able to convert them 1 by 1 using RegExp but I'm sure there is a better way to do this.
new RegExp(r'…'),'...'))),
Thanks for the help.
There's a library called html_unescape that can do that, you can find it here.
The steps to get it working are described there but as a quick reference:
1.- Include the dependency on your pubspec.yaml
dependencies:
html_unescape: ^1.0.1+3
flutter:
sdk: flutter
2.- Install the dependeny
Click on Packagets get while on the pubsec.yaml file
3.- Import it and use it:
import 'package:html_unescape/html_unescape.dart';
void main() {
var unescape = HtmlUnescape();
// prints ’ and …
print(unescape.convert('’ and …'));
}
//EDIT
Just as extra info, this is the google query I used to find this:
"convert html entities string flutter"
I used IonicNative plugin for downloading pdf files.
https://ionicframework.com/docs/native/file-transfer/
I can see download complete using alert,but cannot see any download happening.
private filetransfer: FileTransferObject = this.transfer.create();
const url = 'https://www.example.com/example%20test.pdf';
this.filetransfer.download(url, this.file.dataDirectory + 'example%20test.pdf').then((entry) =>
{
alert('download complete: ' + entry.toURL());
},
(error) => {
alert(error);
});
Is this the correct way to do or am I missing some thing?
This looks like the correct way to do it.
I'm not quit sure what you mean with "you cannot see any download happening", but I'm assuming you can't find the file in the file system (otherwise just let me know).
In this case your saving the file in a private data storage, specified by:
this.file.dataDirectory
If you replace this.file.dataDirectory with this.file.externalDataDirectory, you will find the document in your file system (something like: file:///storage/emulated/0/Android/data/com.project.name).
The ionic native documentation is not that good in this case, see the cordova file plugin documentation instead, where the different possibilitiers are listed:
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#where-to-store-files.
I'm trying to use PreloadJS to load an image. I took the getting started code from http://www.createjs.com/getting-started so,
function loadImage() {
var preload = new createjs.LoadQueue();
preload.addEventListener("fileload", handleFileComplete);
preload.loadFile("assets/preloadjs-bg-center.png");
}
function handleFileComplete(event) {
document.body.appendChild(event.result);
}
Which works great, but changing the URL to a custom one doesn't play so nice:
preload.loadFile("http://localhost:3000/URLthatReturnsAnImageWithoutFileType");
I'm unable to render the image. I'm guessing the loadFile function parses the file type in the provided URL string. Is there a way to tell PreloadJS the provided asset is indeed an image and render it?
According to LoadQueue's documentation, the file type of an item is determined by it's file extension. If it doesn't have an extension, then you can pass in a type property:
preload.loadFile({src:"hello", type:createjs.AbstractLoader.IMAGE});