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.
Related
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!
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')"
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.
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.
I am currently loading dropped files by doing:
var files = e.dataTransfer.items;
for (var i = 0; i < files.length; i++) {
var file = files[i]; //typeof is 'DataTransferItem'
var url = URL.createObjectURL(file);
}
This gets me the object url, which I can then put into a music player. However, when iterating over an inputted folder:
var reader = entry.createReader();
reader.readEntries(function (res) {
res.forEach(function (entry) {
console.log('The entry:', entry);
console.log('The url:', JSON.stringify(entry.toURL()));
});
});
I get files of type FileEntry. According to this I shall be able to do file.toURL() and use that instead of an object url. This does return me an empty string. this seems to be there for a reason, but I have no idea how to fix this. I see something about a blob URL but I have no idea how that would work.
Example
Try to drag files and folders to the output screen and see it yourself
How I fixed it:
from an entry with typeof FileEntry, we can just do .file(callback), where the first parameter in the callback is of type File, which we can then just create an objectURL from:
var reader = entry.createReader();
reader.readEntries(function (res) {
res.forEach(function (entry) {
entry.file(function(file){ //this does the trick
var obj = URL.createObjectURL(file);
}
});
});
Many thanks to dandavis who provided me his javascript code and the approximate line so I could go look for it myself ;)