Download an image URL in protractor - protractor

I need to download an image URL to my project folder's file. I have tried below code for that:
var a = document.createElement('a');
a.download = './files';
a.href = 'https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png';
a.style.display = 'none';
document.body.appendChild(a);
a.click();
But it gives error as ReferenceError: document is not defined.
How can we solve this or how can I download an image URL to a specified folder?
Thanks in advance.

Related

Error:: Cannot retrieve length of file, path = '' (OS Error: No such file or directory, errno = 2) using http.MultipartFile.fromPath

I am trying to make a screen that shows information from the database such as the image and other fields to be able to update.
I get a Cannot retrieve length of file, path, (OS Error: No such file or directory, errno = 2) problem.
When I open the camera the photo is updated correctly.
I think the problem appears because it is not a route that you get using the camera and it is a route that is saved from the database.
So when I don't update or dont open the camera in the Image Picker File, the File image is assigned the path of the database.
They are the same routes of the same photo.
I don't know if I have to do something in php before I get the path from the database when I send it to flutter
Example of a new camera path, just used by the camera and a path that I get from the database, previously saved::
I get this route from the camera
File: '/data/user/0/com.example.rati_app/cache/3b4075c7-03df-471b-b8c0-7b88561ab29f32288.jpg'
i get this route from the data base
fzn/3b4075c7-03df-471b-b8c0-7b88561ab29f32288.jpg
code and image::
////////////////// dart flutter ///////////////
Future UpdateProfileUser(RoutePictureProfile) async {
var Url = Uri.parse("http://.....");
var request = await http.MultipartRequest('POST', Url);
var pic = await http.MultipartFile.fromPath('User_image',RoutePictureProfile);
request.files.add(pic);
var response = await request.send();
}
////////////////////////// php ///////////////////////
get the information from database
<?php
include("Database.php");
$consulta = "select User_p,User_name,Usuario_email,user_´picture from user";
$query = $conex->query($consulta);
$data=array();
header("Content-Type: application/json");
while($row = $query->fetch_assoc()){
$data[]=$row;
}
echo json_encode($data,JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$conex->close();
?>
insert the photo camera
<?php
$imagen = $_FILES['User_image']['name'];
$imagePath = 'fzn/'.$imagen;
$tmp_name = $_FILES['User_image']['tmp_name'];
move_uploaded_file($tmp_name,$imagePath);
?>
enter image description here

cn1 - get file path to image for share()

I'm trying to use the share() method, including an image, but I'm having trouble supplying the proper path to the image. Where should I put the image file, and what is the path (putting in the default package and trying "jar:///myimage.png" didn't work), and why is this not documented clearly?
image can be stored in storage which is following path for window
C:\Users\userName.cn1
and the image can be read by using following codes
InputStream is = Storage.getInstance().createInputStream("tizbn.JPG");
EncodedImage i = EncodedImage.create(is, is.available());
Loading image from default folder
Image i =EncodedImage.create("/tizbn.png");
Loading image From Theme
EncodedImage current = (EncodedImage) fetchResourceFile().getImage("tizbn.png");
The share API works with https://www.codenameone.com/javadoc/com/codename1/io/FileSystemStorage.html[FileSystemStorage] and not with https://www.codenameone.com/javadoc/com/codename1/io/Storage.html[Storage].
You need to save the file into a file system path which is always an absolute path, we recommend using the app home to store files. There is a sample in the developer guide section on the ShareButton covering this:
Form hi = new Form("ShareButton");
ShareButton sb = new ShareButton();
sb.setText("Share Screenshot");
hi.add(sb);
Image screenshot = Image.createImage(hi.getWidth(), hi.getHeight());
hi.revalidate();
hi.setVisible(true);
hi.paintComponent(screenshot.getGraphics(), true);
String imageFile = FileSystemStorage.getInstance().getAppHomePath() + "screenshot.png";
try(OutputStream os = FileSystemStorage.getInstance().openOutputStream(imageFile)) {
ImageIO.getImageIO().save(screenshot, os, ImageIO.FORMAT_PNG, 1);
} catch(IOException err) {
Log.e(err);
}
sb.setImageToShare(imageFile, "image/png");

Unable to display image from cordova.file.documentsDirectory

I am trying to access an image that i download from remote server. My code to download the file is as below :
var targetPath = cordova.file.documentsDirectory + propp+".png";
var trustHosts = true;
$cordovaFileTransfer.download(url, targetPath, options, trustHosts)
.then(function(result) {
console.log("Local file transfer done");
r = angular.toJson(result.nativeURL);
}, function(err) {
// Error
console.log("error");
});
Then I stored tatgetPath in my local sqlite database. In another page I get this from sqlite and try to display with img tag. But it display like broken Image on Emulator as well as on actual device.
My file url is :
file:///var/mobile/Containers/Data/Application/F7B3169B-D8E3-4F62-AD0B-37CFA381F1CC/Documents/home_bg_image.png
I want to display this image as a background image bit I don't understand how to do this.
After downloading the image you have to paste it in platform/android/assets/www/img-- folder to display the image as
var filedirPath = $ionicPlatform.is('android') ? '/android_asset/www/img/' : 'img';
if not find the path of the image and access the file to display for reference please check this link File path
Having any queries reply ..

Facebook change image in page tab

I'm trying to change a facebook page tab image programatically. The idea is when my app will finish the instalation process, it will be change the image of the tab where it place it. After finish the process and give permissions to the app, The response of fb is "unautorized"
{"error":{"message":"(#300) Edit failure","type":"OAuthException","code":300}}
I searched about this error, the most close aproach was: https://developers.facebook.com/bugs/255313014574414/.
I tried the same CURL example described in the error and have the same response.
The strange thing is, when i tried change the image inside fb, it fails too. I think the problem is when the app ask permissions to install in the user page, and don't have enough permits.
But i don't know hot i chage the permit to authorize chage the image of the pagetab.
var fbparams = new Dictionary<string, object>();
string path = #"c:\test.jpg";
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
var picture = new FacebookMediaObject
{
//Tell facebook that we are sending image
ContentType = "image/jpeg",
//Give name to the image
FileName = "test"
};
//Create a new byteArray with right length
var img = tabImageInfo.Media;
//Convert the image content into bytearray
fs.Read(img, 0, img.Length);`enter code here`
//Close the stream
fs.Close();
//Put the bytearray into Picture
picture.SetValue(img);
//Add the image into parameters
fbparams.Add("custom_image", picture);
fb.Post(tab.id, fbparams);

Open local pdf in cordova project with iOS

I've tried to open local PDFs stored in the www/Documents folder in my XCode project. The code I put in .js file is:
Cordova.exec("ChildBrowserCommand.showWebPage", "file:///www/Documents"+pdf );
Where pdf is the name of the file, which changes for every file. It works fine on the simulator but it doesn't work on device. How can I fix this?
Thanks!
I am using below function to load files in childbrowser, it creates the correct local url in case you want to load the internal files:
function loadChildBrowser(isInternal, URL) {
if(isInternal){
var strPath = window.location.href;
var path = strPath.substr(0,strPath.lastIndexOf('/')) + URL;
cb.showWebPage(encodeURI(path));
}
else{
cb.showWebPage(URL);
}
}
Edit
Try this for your case:
function loadChildBrowser(isInternal, URL) {
if(isInternal){
var strPath = window.location.href;
var path = strPath.substr(0,strPath.lastIndexOf('/')) + URL;
Cordova.exec("ChildBrowserCommand.showWebPage", encodeURI(path) );
}
else{
Cordova.exec("ChildBrowserCommand.showWebPage", URL );
}
}