I am using RadAsyncControl but my file validation is failing i have tried to track the issue through this example .. so my scenario says
Wrong file size!
However i have set MaxFileSize property to 20971520
and the file being chosen is 1kb .txt file (notepad)
Here's my code
<telerik:RadAsyncUpload ID="rauEvidenceDocuments" runat="server" AllowedFileExtensions=".doc, .docx, .pdf, .txt. .rtf, .pages, .odt, .ppt, .pptx, .png" MultipleFileSelection="Automatic"
OnClientFileSelected="onClientFileSeleted" OnClientFileUploadFailed="OnClientFileUploadFailed" OnClientValidationFailed="validationFailed" RenderMode="Lightweight" MaxFileSize="20971520">
</telerik:RadAsyncUpload>
function validationFailed(radAsyncUpload, args) {
var $row = $(args.get_row());
var erorMessage = getErrorMessage(radAsyncUpload, args);
var span = createError(erorMessage);
$row.addClass("ruError");
$row.append(span);
//alert('validation failed');
}
function getErrorMessage(sender, args) {
var fileExtention = args.get_fileName().substring(args.get_fileName().lastIndexOf('.') + 1, args.get_fileName().length);
if (args.get_fileName().lastIndexOf('.') != -1) {//this checks if the extension is correct
if (sender.get_allowedFileExtensions().indexOf(fileExtention) == -1) {
return ("This file type is not supported.");
}
else {
return ("This file exceeds the maximum allowed size" /*+ sender._maxFileSize()*/);
}
}
else {
return ("not correct extension.");
}
}
function createError(erorMessage) {
var input = '<span class="ruErrorMessage">' + erorMessage + ' </span>';
return input;
}
P.S. It is a multiselect control
Heyy, so i found the issue it was giving me the wrong reason for validation. i had spaces in AllowedFileExtensions that's what was causing validation to fail.
So Cheers after wasting 2 hrs :)
Related
I'm using dropzone.js to be able to easily upload files and folders. I do not get an notification for empty folders, is there any way to have an event fired for empty folders?
Thank you.
So this is what I came up with, not the most elegant solution, but does what I need to be able to handle emptyfolders. Would be great if dropzone.js had an option for enabling emptyfolders to be returned.
I made the following changes to the dropzone.js
At the very top I added
var passedFolders = [];
// used to store the names of fodlers that were passed, with either files or without
// the key is the path name, the value is true if empty, false if it had contents
Then under the section
var readEntries = function readEntries() {
return dirReader.readEntries(function (entries) {
change it to
var readEntries = function readEntries() {
return dirReader.readEntries(function (entries) {
if (entries.length > 0) {
var _iterator7 = dropzone_createForOfIteratorHelper(entries, true),
_step7;
try {
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
var entry = _step7.value;
if (entry.isFile) {
//There is a a file in the folder, so we can set it's value to false
passedFolders[entry.fullPath.substring(0, entry.fullPath.lastIndexOf(entry.name)-1)] = false //-1 to remove the last slash
entry.file(function (file) {
if (_this5.options.ignoreHiddenFiles && file.name.substring(0, 1) === ".") {
return;
}
file.fullPath = "".concat(path, "/").concat(file.name);
return _this5.addFile(file);
});
} else if (entry.isDirectory) {
//This is just a folder, not a file. Store the folder path information set to true, it will remain true if the folder remains empty
passedFolders[entry.fullPath] = true;
_this5._addFilesFromDirectory(entry, "".concat(path, "/").concat(entry.name));
}
} // Recursively call readEntries() again, since browser only handle
// the first 100 entries.
// See: https://developer.mozilla.org/en-US/docs/Web/API/DirectoryReader#readEntries
} catch (err) {
_iterator7.e(err);
} finally {
_iterator7.f();
}
readEntries();
}
return null;
}, errorHandler);
};
Now passedFolders will contain an associate array, where the key is the pathname and the value is true if it is empty, false if it contained files.
Then under the dropzone init, when the file uploads are complete you can choose what to do with empty folders
this.on('queuecomplete', function (file, json) {
alert("Uploads complete, now we can deal with the empty folders");
for (var key in passedFolders) {
if (passedFolders[key]) {
alert(key);
}
}
});
I am using In Design CC 2019, on my Mac OS. When I am trying to get XMP data for my .indd (InDesign document) using ExtendScript.
I am currently getting the error like this:
XMPFile Does not have a constructor.
Below is my script.
// load XMP Library
function loadXMPLibrary(){
if ( ExternalObject.AdobeXMPScript){
try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}
catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}
}
return true;
}
var myFile= app.activeDocument.fullName;
// check library and file
if(loadXMPLibrary() && myFile != null){
xmpFile = new XMPFile(myFile.fsName, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = xmpFile.getXMP();
}
if(myXmp){
$.writeln ('sucess')
}
There's an issue with your codes logic, you need to make the following change:
Add the Logical NOT operator (i.e. !) to the condition specified for your if statement in the body of your loadXMPLibrary function.
function loadXMPLibrary(){
if (!ExternalObject.AdobeXMPScript) { // <--- Change to this
// ^
try {ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}
catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}
}
return true;
}
You need to add this because currently your if statement checks whether the condition is truthy, i.e. it checks whether ExternalObject.AdobeXMPScript is true. This will always remain false, until the AdobeXMPScript library has been loaded, therefore you're code that actually loads the library never gets executed.
Revised script:
For clarity here is the complete revised script:
// load XMP Library
function loadXMPLibrary() {
if (!ExternalObject.AdobeXMPScript) {
try{ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');}
catch (e){alert('Unable to load the AdobeXMPScript library!'); return false;}
}
return true;
}
var myFile= app.activeDocument.fullName;
// check library and file
if (loadXMPLibrary() && myFile !== null) {
xmpFile = new XMPFile(myFile.fsName, XMPConst.FILE_INDESIGN, XMPConst.OPEN_FOR_UPDATE);
var myXmp = xmpFile.getXMP();
}
if (myXmp){
$.writeln ('success')
}
I'm trying to add a validation system to Jasny Bootstrap Fileinput to validate filesize and image format before continue to next step of the form.
I tried Get file size before uploading without success. This check exists in backend, but as the form is "wizard-like", I want to do this in live mode.
Thanks in advance.
This is how I implemented it for Jasny bootstrap input type in whole project commonly.
Hope this will help some one.
$('.fileinput').on("change.bs.fileinput", function (e) {
var file = $(e.delegateTarget, $("form")).find('input[type=file]')[0].files[0];
var fileExtension = file.name.split(".");
fileExtension = fileExtension[fileExtension.length - 1].toLowerCase();
var arrayExtensions = ["jpg", "jpeg", "png"];
if (arrayExtensions.lastIndexOf(fileExtension) == -1) {
alert('Only Images can be uploaded');
}
else {
if (file["size"] >= 4194304 && (fileExtension == "jpg" || fileExtension == "jpeg" || fileExtension == "png")) {
alert('Max 4 MB of file size can be uploaded.');
$(this).fileinput('clear');
}
}
});
I have this code as an excel downloader. After the excel has been generated.
But I'm having an error. As stated in the question Title.
The error occurs at the line:
var strResponeText = XMLHttpRequestObject.responseText;
var strUrl = "POSSellThroughReportExcelOpener.aspx?getstatus=1&DateFrom=" + hdnDateFrom.value + "&DateTo=" + hdnDateTo.value + "&customer_id=" + hdnCustomerID.value + "&intdisplayby=" + hdnDisplayBy.value + "&monthorweek=" + hdnMonthOrWeek.value;
if (XMLHttpRequestObject) {
XMLHttpRequestObject.open("POST", strUrl);
XMLHttpRequestObject.onreadystatechange = function () {
if ((XMLHttpRequestObject.readyState == 4) && (XMLHttpRequestObject.status == 200)) {
var hdnRedirectUrl = document.getElementById("hdnRedirectUrl");
var strResponeText = XMLHttpRequestObject.responseText;
var intResponse = new Number(strResponeText);
var spanCallBackStatus = document.getElementById("spanCallBackStatus");
var trClose = document.getElementById("trClose");
if (!isNaN(intResponse)) {
if (intResponse == 1) {
spanCallBackStatus.innerHTML = "Excel Report has been generated."
trClose.style.display = "";
Init();
window.location.href = hdnRedirectUrl.value;
}
else {
GetStatus();
}
}
else {
spanCallBackStatus.innerHTML = strResponeText;
}
}
}
XMLHttpRequestObject.send(null);
}
Any help is greatly appreciated.
Many thanks.
UPDATE - FEB 20,2014 3:55PM (PHILIPPINE TIME)
Hi Guys,
I have found the cause of the error, it is because the content-type is called two times. During Page_Load event and at last line of the Generate Excel function which is not supposed to be. That is why the current content-type after the page loads has been replaced after the generate excel function. Hehe my bad I guess.
Anyway thanks for all the help, advice and useful links.
Good day to all. :D
Internet Explorer can't handle binary responses to AJAX requests like XMLHttpRequestObject, as discussed in this question. You need to handle the response in some other way, depending on what you need to do with it.
The title is explicit enough, I want to let the user choose the text file he want to open.
I do not know if there is an explorer or an input field already implemented on processing.
Any help would be great.
Use selectInput. From the Processing reference:
Opens a platform-specific file chooser dialog to select a file for input. After the selection is made, the selected File will be passed to the 'callback' function. If the dialog is closed or canceled, null will be sent to the function, so that the program is not waiting for additional input. The callback is necessary because of how threading works.
I've modified the example sketch they provide in the reference to include loading the file with the loadStrings method.
String[] txtFile;
void setup() {
selectInput("Select a file to process:", "fileSelected");
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
String filepath = selection.getAbsolutePath();
println("User selected " + filepath);
// load file here
txtFile = loadStrings(filepath);
}
}
There is no Implemented method, but you could could make a buffer and monitor key presses like so:
String[] File;
String keybuffer = "";
Char TriggerKey = Something;
void setup(){
//do whatever here
}
void draw(){
//Optional, to show the current buffer
background(255);
text(keybuffer,100,100);
}
void keyPressed(){
if(keyCode >= 'a' && keyCode <= 'z'){
keybuffer = keybuffer + key;
}
if(key == TriggerKey){
File = loadStrings(keybuffer + ".txt");
}
}
when triggerkey is pressed, it loads the file