WhatsApp share using expo-sharing library in Android(React-native) - javascript

I want to share an image file directly to my whatsApp or add it to my whatsApp status i.e I don't want to see any other sharing option when I click on button to share any image.
Currently I am using the following code to share
import * as Sharing from 'expo-sharing';
import * as FileSystem from 'expo-file-system';
const customShare = async (image) => {
const base64result = image.split(',')[1];
try {
let filename = 'share.png'; // or some other way to generate filename
let filepath = `${FileSystem.documentDirectory}/${filename}`;
await FileSystem.writeAsStringAsync(filepath, base64result, { encoding: 'base64' });
await Sharing.shareAsync(filepath, { mimeType: 'image/gif' })
} catch (e) {
alert(e.message);
}
};
But here it is showing all sharing option to choose, is there any way to skip this step and directly open my WhatsApp

Related

I need to get the download URL from Firebase, Storage , using JavaScript, in html , The Picture gets uploaded , but I get no DownloadURL?

When I hit upload the picture gets uploaded to firebase Storage, but i cant seem to get the image url, I can go to the Storage tab on firebase click on the image and click on its ling , copy the link in and then past it into the DATABASE were i need it for display and it will work, But i dont see an image URL or A download URL when i consolo.log the snapshot of the const TASK!
I fear that the method:
const task = uploadBytesResumable(storeref, ImSRC, metdata)
that iam using to upload the image does not produce an image url! Could This be So?
!!!HERE IS ALL THE CODE FOR THE UPLOAD BUTTON !!
Upload.addEventListener('click', (e) =>{
let ImSRC = files[0];
if(ImSRC == null ){
alert('no picture selected');
}else{
const metdata = {
contentType: ImSRC.type
}
const storeref = sRef(storage,"UsersProPic/" + cUserID);
const task = uploadBytesResumable(storeref, ImSRC, metdata).then((snapshot)=>{
console.log(snapshot);
function getData(){
snapshot.getDownloadURL().then(function(url){
ProPicUrl = url;
})
}
console.log(ProPicUrl);
});
}
});
Getting the download URL from Firebase Storage is (like uploading the data itself) an asynchronous operation. Just like any code that needs to run after the upload has completed needs to be inside the then() block for that task, the code that needs to run after the download URL has been determined has to be inside the then() block for that task too.
So:
const storeref = sRef(storage,"UsersProPic/" + cUserID);
const task = uploadBytesResumable(storeref, ImSRC, metdata).then((snapshot)=>{
console.log(snapshot);
function getData(){
snapshot.getDownloadURL().then(function(url){
ProPicUrl = url;
console.log(ProPicUrl);
})
}
});

Upload image from URL via chrome extension

I'm trying to build chrome extension that can upload image from URL to any input:type.
It is 100% possible because i found one extension which implements that i want.
Link to this extension: https://chrome.google.com/webstore/detail/upload-image-from-url/eiglgndkjiabiepkliiemoabepkkhacb?hl=en
This extension finds all inputs of file type.
Then you just need to paste a link to image from remote server.
screenshot of this extension 1
screenshot of this extension 2
I need the code which can fill known input:file with image from URL.
My use case was a little different (to automate some uploading in the background), but in any case I was able to get this working like so...
content_script.js
async function createFile(url: string) : Promise<File> {
let response = await fetch(url);
let data = await response.blob();
let metadata = {
type: 'image/jpeg'
};
return new File([data], "test.jpg", metadata);
}
chrome.runtime.sendMessage({load: "true"},async function(response) {
if (response.url) {
const designFile = await createFile(response.url);
// find the file input element and trigger an upload
const input = document.querySelector('input.jsUploaderFileInput') as HTMLInputElement;
const dt = new DataTransfer();
dt.items.add(designFile);
input.files = dt.files;
const event = new Event("change", {
bubbles: !0
});
input.dispatchEvent(event)
}
});
background.js
chrome.tabs.create({url: 'https://www.somepagewithanuploadform.com'});
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
if (message.load == "true") {
sendResponse({url: "https://i.stack.imgur.com/C4ndg.jpg"});
}
});

Lightshot Screenshot image preview from the URL using JavaScript

I've created a support forum where people frequently attach images taken by Lightshot Screenshot. They generally add the uploaded URL (like https://prnt.sc/ujaclu) to the forum. Basically all the images attached by uploading are previewed to the forum. But from the Lightshot URL, I cannot get any image.
Could anyone help me to parse the Lightshot URL (https://prnt.sc/ujaclu) as I can use it to an src URL of <img /> tag using JavaScript?
Note: I didn't get any hint on how to do it. I am completely stuck on it.
I wrote a solution for the Lightshot image extraction using Javascrit : LightShot Image Extractor
Here is the code:
const cheerio = require('cheerio')
const axios = require('axios')
/**
* Extracts the jpg url from a LightShot page
* lightshot_image('http://prntscr.com/dki21q')
* http://image.prntscr.com/image/1aaf571d0adf4aa098eb565bbb196af6.png
*/
async function lightshotImageExtractor(url) {
try {
const { data } = await axios.get(url)
const imgUrl = parseHTML(data)
return imgUrl
} catch (err) {
console.log(err)
return null
}
}
function parseHTML(html) {
const $ = cheerio.load(html)
const rows = $('.screenshot-image')
if (rows.length > 0 && rows[0].attribs && rows[0].attribs.src) {
return rows[0].attribs.src
}
return null
}
lightshotImageExtractor('http://prntscr.com/dki21q').then((url) =>
console.log(url),
)
The link you are trying to use to show the image is not images url. It is url of a page. That's why it is not showing any image.
This is the actual url of the image https://image.prntscr.com/image/EdCTchd1TLit-Gg1Mtt-pg.png
Contact with them and ask them if they can help you with their link decryption.

Using Native File System API to save file to a specific location without user interaction?

I have my own custom system that needs to create txt files in order to print cash receipts when there is a new order. I need those files to be saved locally to the computer to a specific location, but is there a way to save the file to that location without prompting the user to choose the file location? Is it possible if you create your own FileSystemFileHandle class and then pass it as a handle?
$('.save').click(function() {
saveToFile('from website');
});
async function saveToFile(content) {
const opts = {
type: 'save-file',
accepts: [
{
description: 'Text File',
extension: ['txt'],
mimeType: ['text/plain'],
}
]
}
const handle = await window.chooseFileSystemEntries(opts); // don't to that
// create custom FileSystemFileHandle and point to the file location?
const handle = FileSystemFileHandle;
const writable = await handle.createWritable();
await writable.write(content);
await writable.close();
}
This can't be done with the File System Access API, but ironically automatically triggered downloads are still a thing with the <a download> approach.
const a = document.createElement('a');
// undefined
a.download = 'example.txt';
// "example.txt"
a.href = URL.createObjectURL(new Blob(['yolo'], {type : 'text/plain'}));
// "blob:https://example.com/8d494f54-499d-4f32-bdb4-ff047e8c60af"
a.click();
// undefined
// Downloads a file `example.txt` to your Downloads folder

Convert PHAsset/AVAsset to mp4 video in Nativescript app

I use the nativescript-imagepicker-plugin for a filepicker.
This returns a PHAsset.
I have to copy it to a temporary directory to upload it.
Im new in iOS, so I tried a bit:
const options = PHVideoRequestOptions.new();
options.version = PHVideoRequestOptionsVersion.Current;
PHImageManager
.defaultManager()
.requestAVAssetForVideoOptionsResultHandler(
phAsset
, options
, (avAsset, audioMix, info) => {
try {
const tempFilePath = path.join(tempFolderPath, `${Date.now()}.mp4`);
const targetURL = NSURL.fileURLWithPath(tempFilePath);
const exportSession = AVAssetExportSession.alloc(avAsset, AVAssetExportPresetPassthrough);
exportSession.outputUrl = targetURL;
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.exportAsynchronouslyWithCompletionHandler(() => {
console.log(exportSession.status);
});
}
catch (e) {
console.log(e);
}
}
);
My code crashes without error, so I don't know where to start to debug.
I want a MP4, to show it in web too.
At the end I need a string (path) to a mp4 file to upload id with nativescript-background-http.
Your syntax seems to be wrong
const exportSession = AVAssetExportSession.alloc().initWithAssetPresetName(avAsset, AVAssetExportPresetPassthrough);
exportSession.outputURL = targetURL;

Categories