I use uploadify plugin v3.2.1, the problem is, I use file limit, but when I upload file above that limit it is not showing any error message. I've tried to find on google and found out that I need more codes just like this
'onSelectError' : function() {
alert('The file ' + file.name + ' returned an error and was not added to the queue.');
}
But still not work, anyone know? Maybe is in query file, but I don't know how to modify it.
Try
onSelectError': function (file, errorCode, errorMsg) {
alert('The file ' + file.name + ' returned an error and was not added to the queue.');
}
Related
I need to my extension can generate and save text file inside downloads folder. Just give me example of code how to do it.
The downloads API is what you are probably looking for:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/downloads
The downloads.download() function lets you download a file from a URL to your Downloads folder. Here is the example based on the Downloads.download() page.
function onStartedDownload(id) {
console.log('Started downloading: ' + id);
}
function onFailed(error) {
console.log('Download failed: ' + error);
}
var downloadUrl = "https://www.mozilla.org/media/img/home/2018/cards/irl-season-3.821df676279d.png";
var downloading = browser.downloads.download({
url : downloadUrl,
filename : 'mozilla-home.png',
conflictAction : 'uniquify'
});
downloading.then(onStartedDownload, onFailed);
If you need to download data created in Javascript, then you'll first have to create a URL for that data using URL.createObjectURL()
I am using the http.getFile function to download files from an api. I am having a issue where files are still created, even though the url passed to getFile is invalid or returning errors. After some research it appears the getFile will always create a new file, is there a way to prevent getFile from creating a new file if the url is invalid?
The only work around I can think is to check the file size after calling the getFile and deleting it if there is no data?
In the example below I was tying to use the File.exists, but it always returns true.
return http.getFile(fullUrl, filePath)
.then(function(r){
// Test - Check if file Exists
console.log("Check File Exist: " + fs.File.exists(filePath));
}, function(error) {
});
Just check if the "fullUrl" is a valid url before requesting:
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*#)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%#!\-\/]))?/
var isUrlValid = regexp.test(fullUrl);
if(isUrlValid){
http.getFile(fullUrl, filePath)
}
To custom the applications, I have defined a new format with ckan 'csv + carte'.
Actually, it's a CSV file with a view map and a DataExplorer view. So , i want to open this format with the view DataExplorer too, but i have the problem with the dataproxy: Could not load view: DataProxy returned an error (Data transformation failed. Exception: Resource type not supported 'csv + carte')
So i don't know exactly how to tell the dataproxy to consider it as a csv format so it can be open with the DataExplorer.
What i've done is to modify the code under ckan-docker_src\ckan\ckan\public\scripts\application.js; especially this part like that:
else if (resourceData.formatNormalized in {'csv': '', 'xls': '', 'tsv':'', 'csv + carte':''}) {
// set format as this is used by Recline in setting format for DataProxy
console.log("CSV");
**// Treat 'csv + carte' format like csv
if(resourceData.formatNormalized === 'csv + carte')
resourceData.format='csv'
else
resourceData.format = resourceData.formatNormalized;**
resourceData.backend = 'dataproxy';
var dataset = new recline.Model.Dataset(resourceData);
var errorMsg = CKAN.Strings.errorLoadingPreview + ': ' +CKAN.Strings.errorDataProxy;
dataset.fetch()
.done(function(dataset){
dataset.bind('query:fail', function(error) {
$('#ckanext-datapreview .data-view-container').hide();
$('#ckanext-datapreview .header').hide();
$('.preview-header .btn').hide();
});
initializeDataExplorer(dataset);
$('.recline-query-editor .text-query').hide();
})
.fail(function(error){
if (error.message) errorMsg += ' (' + error.message + ')';
showError(errorMsg);
});
}
But, it doesn't work. Where do i have to modify to take into account this new format? Thank you for your help
When I upload a file with Krajees Bootstrap Fileinput, I perform a server side validation of the file. When something goes wrong, I output a JSON-Object simply with {error:'Something went wrong'}. The Plugin displays the error perfectly.
But then: When I press again "upload" just after that, the $_FILES array in the called submit PHP script is empty. This means, the plugin does not send the file again even if it has notified that an error has occurred.
Why would the plugin only upload the file once even if it detects that there was an error? Are there any methods that can "reset" the "uploaded state" of the file? (I'm only uploading one file).
I already checked the file events but none of them brought me to the desired result, instead they kind of destroyed the whole upload form with certain buttons being suddenly disabled and so on.
I finally found out the exact point, where the problem could be solved:
On line 1705 in the function updateUploadLog, the function self.updateStack is called. This call simply clears the file stack and causes a later process to empty the form input. Simply commenting out this line does the trick, but only if you reload after success, because somehow fnSuccess is also called when an error is found.
#Angad thank you very much for your solution triggering input, thanks to that I found a place to start the search again ;)
I see that the Github Issue says this isn't currently supported, but it seems relatively uncomplicated to fork this project and bend it to your needs. All the fnError ='s you'll find in a Cmd + F search inside fileinput.js are where you need to look.
Take for instance here: https://github.com/kartik-v/bootstrap-fileinput/blob/d5ed3ee989edbd5d67b8cf4bdadc9f3c18609965/js/fileinput.js#L1897
This is for the batch file-upload that currently looks like this:
fnError = function (jqXHR, textStatus, errorThrown) {
var outData = self._getOutData(jqXHR), errMsg = self._parseError(jqXHR, errorThrown);
self._showUploadError(errMsg, outData, 'filebatchuploaderror');
self.uploadFileCount = total - 1;
if (!self.showPreview) {
return;
}
self._getThumbs().each(function () {
var $thumb = $(this), key = $thumb.attr('data-fileindex');
$thumb.removeClass('file-uploading');
if (self.filestack[key] !== undefined) {
self._setPreviewError($thumb);
}
});
self._getThumbs().removeClass('file-uploading');
self._getThumbs(' .kv-file-upload').removeAttr('disabled');
self._getThumbs(' .kv-file-delete').removeAttr('disabled');
};
I'd try modifying this to:
fnError = function (jqXHR, textStatus, errorThrown) {
if (!myError.equals(textStatus)) { // A service-like impl. injection would be sexier
var outData = self._getOutData(jqXHR), errMsg = self._parseError(jqXHR, errorThrown);
self._showUploadError(errMsg, outData, 'filebatchuploaderror');
self.uploadFileCount = total - 1;
if (!self.showPreview) {
return;
}
self._getThumbs().each(function () {
var $thumb = $(this), key = $thumb.attr('data-fileindex');
$thumb.removeClass('file-uploading');
if (self.filestack[key] !== undefined) {
self._setPreviewError($thumb);
}
});
self._getThumbs().removeClass('file-uploading');
self._getThumbs(' .kv-file-upload').removeAttr('disabled');
self._getThumbs(' .kv-file-delete').removeAttr('disabled');
} else {
self._ajaxSubmit(fnBefore, fnSuccess, fnComplete, function() {
// TODO: Second time failure - handle recursively or differently? :-)
);
}
};
Hope this helps!
What I'm trying to implement is giving the users the ability to export the grid data to an excel file and download it, with the help of a file save dialog.
Here's how I have coded it right now -
In Javascript -
$.post("/irn/Identifier/Download", { "columnValues": columnValues });
In the Identifier controllers Download action -
public FileResult Download(string columnValues)
{
DTData headlineRows = (DTData)Newtonsoft.Json.JsonConvert.DeserializeObject(columnValues, typeof(DTData));
var e = new Services.DownloadToExcel();
return File(e.WriteData(headlineRows), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "testfile.xlsx");
}
In the DownloadToExcel class, inside the WriteData function I have -
//Here, I'm using the EPPlus library to write the column data to an excel file and then i'm returning the data as a byte array -
//Some code that writes the data
return packages.GetAsByteArray();
When I run this code, I expect to see a File Save Dialog in the browser, but nothing happens. There aren't any errors on the C# or JavaScript side. Can anyone tell me what i could be doing wrong?
bit late but I was having a similar issue. To solve it I used JSON.stringify(columnValues) on the client to convert my data into a json string before sending it to the controller.
Then instead of using
$.post("/irn/Identifier/Download", { "columnValues": columnValues });
try
var columnValuesString = JSON.stringify(columnvalues);
window.location = '/irn/Identifier/Download?columnvalues=" + columnValuesString';
Changing the $.post() to a window.location makes it work.
Then you can deserialize the json string in the controller and your Open/Save dialog should appear after hitting your link.
I hope this helps someone else. Let me know and I can post my code if needed.
Thanks.
If you're testing the site in Internet Explorer, try the following:
Open Internet Options -> Advanced. Click Reset. You can also choose to Restore Advanced Settings.
Open Internet Options -> Security. If zones have been changed at all, click "Reset all zones to default level".
Changes to these settings may affect whether or not Internet Explorer accepts file downloads.
More information here: http://answers.microsoft.com/en-us/ie/forum/ie8-windows_other/ie-8-will-not-let-me-download-any-files-music-pdf/bc59ba24-866b-4dbf-93f2-85ebb9912c2c
You should use IFrame to help downlaoding the file.
function postToIframe( url,data) {
var target = "downloadIFrame";
$('<iframe name="' + target + '" style="display:none"/>').appendTo('body');
$('body').append('<form action="' + url + '" method="post" target="' + target + '" id="postToIframe"></form>');
$.each(data, function (n, v) {
$('#postToIframe').append('<textarea name="' + n + '">' + v + '</textarea>');
});
$('#postToIframe').submit().remove();
}
I solved this but forgot to update here -
This worked -
Inside my class -
private const string MimeType = "application/vnd.openxmlformats-
officedocument.spreadsheetml.sheet";
private ExcelPackage package = new ExcelPackage();
private FileContentResult excelFile;
Write data using EPPlus
...
...
...
excelFile = File(package.GetAsByteArray(), MimeType, FileName);
return excelFile;