My machine is connected with a scanner. The scanner can return a couple of images and I can get the paths of these images in the web page. Then I want to upload these images using Plupload plugin. Now I can get these file using ActiveX. But when I call the AddFile function, it doesn't work. It seems like the file returned by ActiveX is not suitable for the AddFile function. How can I do ?
//scanFilePath such as: D:\image001.jpg
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f1 = fso.GetFile(scanFilePath);
var i_upload = $("#uploader").pluploadQueue();
var tmp = scanFilePath.split("\\");
var filename = tmp[tmp.length-1];
i_upload.addFile(f1, filename);
Related
My code (I would have made this runnable except for the filesaver.js dependency (https://github.com/eligrey/FileSaver.js/))
var array = new Array();
array[0] = 'a'; //.replace(/<br>/g, '\n\t');
var blob = new Blob(array, {type: "text/plain;charset=utf-8"});
var pub = function () {
console.log('hello');
console.log(new Error().stack);
}
let loc = window.location.pathname.substring(window.location.pathname.lastIndexOf("/") + 1);
let obj = window.saveAs(blob, loc);
obj.onwriteend = pub;
// obj.onerror = pub;
obj.onabort = pub;
There is no issue with the file saving
The issues are that the onwriteend handler gets called before I've even picked a file, and onabort never gets called. I don't know what's going on here. I'm trying to get a callback when the content is written to disk or when the file chooser is aborted.
FileSaver.js is limited by its use of the save link tunnel: It's declared listeners do not work, and there is no way to get the name and directory of saved file, or even to know if the file was saved at all.
Using browser-nativefs instead of FileSaver.js is good in that it uses established FileHandler / File API. But browser-nativefs is too limited for my purposes: You cannot get the directory / URI / URL of the file download. The only way to provide this "link" is through the (FileSave.js) browser file download process outside of the scope of what JavaScript can see.
I need to access list of files in "D//logs" folder from my machine using javascript.
And then display them as hyperlink in a html page. I tried to acheive this using ActiveX, but accessing files is throwing error.
(Developing only for Internet explorer)
var fso = new ActiveXObject("Scripting.FileSystemObject");
var xx = fso.GetFolder("d:\\logs");
var yy = new Enumerator(xx.Files);
var zz = new Enumerator(yy.item()); // how to acess files inside folder
I'm developing an app and trying to upload an image in base64 to my server. Testing the code via web it works perfectly! And when I convert the image in base64 to File, it returns me the following object:
But when I try to make the same thing in my mobile app running on an Android device, the same code creates to me the following File object:
What is happening? I call the function to convert my base64 image to File as this:
var blob = new Blob([photoBase64], {type: 'image/png'});
var filePhoto = new File([blob], "employeePhoto.png");
In first image (which worked) I was running on web browser.
In second image (not worked) I was running on Android app.
It is the same code...
It appears that File constructor have different behavior in web browser and Android app. I am not understanding this. Passing the parameters to File constructor in the same order create different File objects (as the described on images).
If you are trying to convert base64 to File, you can utilize part of canvas.toBlob() polyfill
var base64 = "data:image/png,base64,"; // data URI
var binStr = atob(base64.split(",")[1]),
len = binStr.length,
arr = new Uint8Array(len);
for (var i = 0; i < len; i++) {
arr[i] = binStr.charCodeAt(i);
}
var file = new File([arr], "image");
var img = new Image;
img.onload = function() {
document.body.appendChild(this);
URL.revokeObjectURL(url);
}
var url = URL.createObjectURL(file);
img.src = url;
I need to upload image file into the sharepoint 2010 picture library using java script...
requirement is --
1.we have File Upload control
2.And, we have to upload image file from that file upload control
Please see code...But this code is not working (showing "Undefined object" exception for 'File' or 'FileInfo')
If any body have better solution that would be nice.
Thanks in advance.
<script>
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('Test');
//var fStream = (new FileInfo(uploadimagepath)).OpenRead();
var fStream = File.OpenRead(uploadimagepath);
//var fStream = FileUpload.PostedFile.InputStream;
//var contents = new byte[fStream.Length];
var newPic = oList.RootFolder.Files.Add(phototitle, fStream);
var oItem = newPic.Item;
oItem.set_item('Title', phototitle);
oItem.update();
oList.Rootfolder.Update();
clientContext.load(oItem);
</script>
you cannot use the uploadimagepath, it gives you the path from the client.
instead use the file stream which is sent from client to server.
check this url for understanding the file upload control better
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.postedfile.aspx
I created a Windows 7 Gadget and I need to create a place on each user's computer to store the Settings.ini file (Created from my SettingsManager.js file). The application packaging team at my company recommends I use
%LOCALAPPDATA%\Microsoft\Windows Sidebar\
and then add
Gadgets\iMon.Gadget\
subfolders. This is so each user's settings are stored in a unique location and won't be changed by any other applications or gadgets.
Do I need to use something along the lines of
var fso = new ActiveXObject("Scripting.FileSystemObject");
var folder = fso.CreateFolder("path");
Any help on how to do this would be appreciated.
Update: I found how to get the %localappdata% path, but I still need to create the new folder. Here's what I've tried without success:
var wshshell = new ActiveXObject("wscript.shell");
var localAppData = wshshell.ExpandEnvironmentStrings("%localappdata%");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var filePath = localAppData + "\\Microsoft\\Windows Sidebar\\Gadgets\\iMon.Gadget";
I'm not sure I understand what you're trying to do here. is iMon.Gadget the name of your gadget? If so, this folder is automatically created for you upon installation of the gadget when the .gadget archive is executed. All the gadget's files and folders will be unpacked to
%LOCALAPPDATA\Microsoft\Windows Sidebar\Gadgets\iMon.gadget\
In your code, you can then proceed to manipulate files within this folder (and it's subfolders). To get the full path, you use
var gadgetPath = System.Gadget.path;
For example:
var oFile,
gadgetPath = System.Gadget.path,
oFSO = ActiveXObject("Scripting.FileSystemObject");
oFile = oFSO.CreateTextFile(gadgetPath + "\\test.txt", true);
oFile.WriteLine("Test.");
oFile.Close();