Firebase Bulk json upload - javascript

I am new in Firebase.I haven't huge knowledge on the firebase.I want a bulk file uploader.
Suppose I have a file uploader in HTML.Using this a CSV/XML file will upload from a HTML.I convert this CSV/XML file in JSON(Array of JSON) then I want to upload this file in firebase.I have already converted and uploaded this file in firebase.But I face some problem, when file size is going big it takes too much time.
$rootScope.showLoader = true;
usSpinnerService.spin('spinner-1');
var ref = firebase.database().ref().child('Cars')
var newItem = $firebaseObject(ref);
var obj = {};
var count = 0;
for (var i = 0, len = jsonFile.length; i < len; i++) {
newItem[jsonFile[i]["DealerID"]] = jsonFile[i];
newItem.$save().then(function() {
count++;
if (count === (jsonFile.length - 1)) {
$rootScope.showLoader = false;
usSpinnerService.stop('spinner-1');
toastr.success('Successfully Upload this file');
}
})
}
This is my code. I use here angularfire service for this.
Can anyone give example how I optimize the time? It will be helpful for me. I can't use any server here.

Related

Automating Photoshop with JS

I had to place videos(mp4-files) in one photoshop document. I thought it would be easier to find a solution with png/jpg, and then project it on mp4. but the fact is that photoshop saving png/jpg and mp4 in different ways. Therefore, despite the fact that there is an import solution, I have difficulties with exporting mp4 by code.
I have 2 arrays of mp4 files and each mp4 from the first array needs to be overlaid on each of the second and saved by mp4. I solved the problem by uploading a video to an open photoshop file with a simple code:
function replaceContents(newFile) {
var docRef = app.open(newFile);
return docRef;
}
function importVideos(order_number) {
var doc = app.activeDocument;
var file = new File('E:/path/' + order_number + '.mp4');
// open a new document with needed video
var docTemp = replaceContents(file);
// copy opend layer with video from new doc to my main doc
var layer = docTemp.activeLayer.duplicate(doc.layerSets.getByName(color), ElementPlacement.PLACEATEND);
// close new unnecessary doc
docTemp.close(SaveOptions.DONOTSAVECHANGES);
layer.name = order_number;
return layer;
}
Here is the code for saving videos and in doExport() doc should be saved as a video.
function Saving(color) {
var array1 = app.activeDocument.layerSets.getByName('s');
var array2 = app.activeDocument.layerSets.getByName(color);
for (i = 0; i < 5; i++) {
array1.artLayers[i].visible = true;
for (j = 0; j < 5; j++) {
array2.artLayers[i].visible = true;
doExport();
array2.artLayers[i].visible = false;
}
array1.artLayers[i].visible = false;
}
}
So a new question: how to export a video from photoshop with a code with the ability to specify the file name and the save path?
P.S. if you do this through Actions, you can't enter input parameters like the name of the saved file, it seals the Action as you did it.
If you know how to create arguments for Actions, you are welcome!

document.createElement background Image of local path [duplicate]

I am not able to get the image path in javascript, below is the code
for (let i = 0; i < 10; i++)
{
const themeButton = document.createElement('button')
if (i === 0)
{
themeButton.style.backgroundImage = "url('../assets/Pngs/ThemesIcon/NewTheme.png')"
//themeButton.style.backgroundImage = `url(https://i.postimg.cc/wMT2jLG7/Group-4807.png)`
}
else
{
themeButton.style.backgroundImage = "url('../assets/Pngs/ThemesIcon/NewTheme.png')"
}
themeButton.classList.add('colorBtn')
themeButton.style.backgroundRepeat = 'no-repeat'
themeButton.style.backgroundSize = '374px 180px'
container.appendChild(themeButton)
}
if i use url it is working for local path it is not working.
themeButton.style.backgroundImage = `url(https://i.postimg.cc/wMT2jLG7/Group-4807.png)`
Folder structure is:
App
Files
assets
Files/uiController.js --> i am accessing image
assets/Pngs/ThemesIcon/Theme1.png --> image folders
According to the folders structure, you provided.
You need backward by one folder with ../.
So the path will be
themeButton.style.backgroundImage = "url('../assets/Pngs/ThemesIcon/Theme1.png')"

Convert local path URI to File or Blob

I am working on a copy and paste feature for my website, so here is my problem. When i copy an image directly from a webpage it works as it should (the first if statement on the code), but if i am trying to copy a image from my own computer a i get a local path (like the one in the else statement)
$scope.pasteImage = function(eventPaste)
{
$scope.uploading = true;
var promises = [];
var items = (eventPaste.clipboardData || eventPaste.originalEvent.clipboardData).items;
for (var i = 0; i < items.length; i++)
{
var blob = null;
if (eventPaste.originalEvent.clipboardData.items[i].type.indexOf("image") == 0 || eventPaste.originalEvent.clipboardData.items[i] == 0)
{
blob = eventPaste.originalEvent.clipboardData.items[i].getAsFile();
}
else
{
var file = new File("file:///home/oem/testabc/vembly/source/server/images/pregnant.png")
console.log(file)
}
}
console.log(eventPaste)
console.log(blob)
var files = [blob];
uploadService.uploadMultiple(files)
}
so, my question is if its possible to transform that file (else statment) into a blob so i can use it in the uploadMultiple(files) funtction that i have.
No.
It would be a huge security problem if any website could use JavaScript to read data from any file path on your system it happened to guess existed.

Get APK package name

Can I get APK package name from uploaded file in JS?
I'm using HTML5 to upload the file and I would like to get the package name of the selected file.
<input type="file"/>
Is it possible?
Finally, I used the amazing JSZip library to get the AndroidManifest.xml content and convert its content to searchable string using the following code:
function getPackageName(apkBlobAsByteArray) {
// Unzipping zip blob
var zip = new JSZip(apkBlobAsByteArray);
// Getting AndroidManifest.xml and decompress it
var androidCompress = zip.files['AndroidManifest.xml'];
var androidNonCompress = androidCompress._data.getContent();
// Reading to content to a searchable string
var packageNameArray = [];
var textArray = String(androidNonCompress).split(',');
for (var i = 0, len = textArray.length; i < len; i++) {
if (textArray[i] !== 0) {
packageNameArray.push(textArray[i]);
}
}
// Searching for package name
var startPattern = 'manifest';
var androidText = String.fromCharCode.apply(null, packageNameArray).toString().toLowerCase();
var packageName = androidText.substring(androidText.indexOf(startPattern) +
startPattern.length, androidText.indexOf('uses'));
// Remove version from package name
packageName = packageName.substring(0, packageName.indexOf(packageName.match(/\d+/)[0]));
return packageName;
}
Nowadays you can use app-info-parser from https://github.com/chenquincy/app-info-parser.
In your browser you can use JS Deliver to include a script tag pointing to https://cdn.jsdelivr.net/gh/chenquincy/app-info-parser/dist/app-info-parser.min.js.
The code may be like:
var parser = new AppInfoParser(files[0])
parser.parse().then(function (result) {
console.log('app info ----> ', result);
console.log('icon base64 ----> ', result.icon);
}).catch(function (err) {
console.log('err ----> ', err);
});

Maximum files of a directory that can be read by FileReader#readEntries in JavaScript

I'm creating a Chrome application. I must read the files of a directory and I am using the DirectoryEntry API and DirectoryReader API.
My problem is that the maximum files read using DirectoryReader#readEntries is 100, the first 100 (alphabetical order)
var reader = currentDir.createReader();
var read = reader.readEntries.bind(reader, function(files) {
for ( var i = 0; i < files.length; i++){
if (files[i].name == nameSearches){
callback(files[i]);
}
}
})
callback(undefined)
}
read();
The value of files.length is 100 and there are more files in the directory
I'm not sure if this limitation is about Google Chrome, Google Chrome Applications, Javascript... and if this limitation can be overcomed
With the solution marked the result code is this:
var reader = currentDir.createReader();
var read = reader.readEntries.bind(reader, function(files) {
if (files.lenght == 0) {
callback(undefined);
}
for ( var i = 0; i < files.length; i++){
if (files[i].name == nameSearches){
callback(files[i]);
}
}
})
read();
}
read();
Read the docs you linked!
The only method for this interface, readEntries() is for listing all
the files and folders in a directory. To list all the entries, you
need to do the following:
Call directoryEntry.createReader() to create a new DirectoryReader.
Call readEntries().
Continue calling readEntries() until an empty
array is returned. You have to do this because the API might not
return all entries in a single call.

Categories