Uploading file size check Grails - ajax

I am facing a problem regarding file uploading in Grails.
I would like to check the file size runtime after opening from the windows explorer and give me the error message if any condition fails.
I have a file uploading window where I have 3 file choose options. I would like to check each three files not to be more than 5MB. When I click on Browse button then my system explorer opens and I choose file.
Is there any way to check file size while selecting the file using javascript/ Ajax call? And if the file size is exceeds than the explorer show again to choose another file.

About this issue, there is a plug-in called file-uploader to the rescue.
With this plug-in you can define some restrictions in config.groovy. Here is an example:
fileuploader {
avatar {
maxSize = 1024 * 256 //256 kbytes
allowedExtensions = ["jpg","jpeg","gif","png"]
path = "/tmp/avatar/"
}
docs {
maxSize = 1000 * 1024 * 4 //4 mbytes
allowedExtensions = ["doc", "docx", "pdf", "rtf"]
path = "/tmp/docs/"
}
}

Related

error when specify customSnapshotsDir outside cypress folder

When i run my test i dont want to save any screenshots on the agent machine
i want to save these images to custom directory
when i try to do this i am getting this error RangeError: Maximum call stack size exceeded. this works fine if i give a folder path inside cypress directory like this cypress\my folder
Can we actually save screeenshot files to a different folder path than the cypress directory?
addMatchImageSnapshotCommand(
{
failureThreshold: 0.00, // threshold for entire image
failureThresholdType: 'percent', // percent of image or number of pixels
customDiffConfig: { threshold: 0.0 }, // threshold for each pixel
capture: 'viewport', // capture viewport in screenshot
customSnapshotsDir:'C:\foldername',
customDiffDir:'C:\foldername'
}
);
You can change the default path to the screenshot in the cypress.json file.
Just add the screenshotsFolder property.
{
"screenshotsFolder": "./my/custom/path"
}

File access permission in Swift on OSX

I'm using:
let dialog = NSOpenPanel()
to get a file URL.
I'm then reading in the contents of the text file with:
let content = try String( contentsOf: dialog.url)
This works!
I'm then trying to read in another text file in the same directory with a different extension:
let b = dialog.url?.deletingPathExtension()
// Add the new file extension
let c = b?.appendingPathExtension("TSN")
let content2 = try String( contentsOf: c)
With this I get:
"The file “FLO5.TSN” couldn’t be opened because you don’t have permission to view it."
If I try and open the .tsn file with a URL from a NSOpenPanel() dialog result it works. I need to open several data files from this same directory with different extensions. Is there a way to do this?
set off sandbox!!)
Xcode 9 and later enables sandboxing by default, which severely limits interactions with the system.
Select your target, then Capabilities and set Downloads Folder to Read/Write:
In my case, solve it's startAccessingSecurityScopedResource
Example:
let selectedFile = try result.get() // get path to file
do {
// get access to open file
if selectedFile.startAccessingSecurityScopedResource() {
let path = selectedFile.path
let data = NSData(contentsOfFile: path)
print(data) // array bytes
selectedFile.stopAccessingSecurityScopedResource()
}
} catch {
// Couldn't read the file.
print(error.localizedDescription)
}
Apple wiki about this feature https://developer.apple.com/documentation/foundation/nsurl/1417051-startaccessingsecurityscopedreso

Can I use Basil.js to get images from a URL?

I am a novice user at ExtendScript, Basil.js & Javascript.
After seeing the project http://basiljs.ch/gallery/ending-the-depression-through-amazon/ I wondered if it is possible to simply get the Basil.js Script/ Extendscript/Indesign to grab images from a webpage and insert it directly into a indesign document.
I am a beginner so if someone had a complete script, from directory, functions... with example url, import, save, place.... ?
This is in the hope that I could simply put an address into the script and it would harvest all images on the webpage and put them into a indesign document?
I tried their example http://basiljs.ch/tutorials/getting-images-from-urls/
but when I copy that and run it in extend script it is just searching my computer...
UPDATE*
#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basil/basil.js";
function draw() {
var url = "https://raw.github.com/basiljs/basil.js/master/lib/basil.png";
// download the url to a default location, filename according to url:
// -> "the project folder" + data/download/basil.png
//b.download(url);
// download url to a specific location in the project folder:
// -> "the project folder" + data/download_images_files/basil_logo.png
// b.download(url, "download_images_files/basil_logo.png");
// download url to a specific location e.g. to your desktop
// -> ~/Desktop/basil_logo.png
var newFile = new File("~/Desktop/basil_logo.png");
b.download(url, newFile);
}
b.go();
... It finds in Error in Basil's Core.js #
var runDrawOnce = function() {
app.doScript(function() {
if (typeof glob.draw === 'function') {
glob.draw();
}
}, ScriptLanguage.javascript, undef, UndoModes.ENTIRE_SCRIPT);
};
Console says...
Using basil.js 1.08 ...
sh ~/Documents/basiljs/bundle/lib/download.sh /Users/jamestk/Desktop (Address here, I don't have the sufficient reputation on stack overflow)
Basil.js Error -> b.shellExecute(): Error: sh: /Users/jamestk/Documents/basiljs/bundle/lib/download.sh: No such file or directory
The easiest way would probably be to us the b.shellExecute(cmd) command to run a shell script that downloads your images.
You could use wget from shell to download all images from an url, see this question: How do I use Wget to download all Images into a single Folder
You should make sure then to save the images in the documents data directory. After that, you could get all images by using the Folder object's getFiles() method:
var myImagesArray = Folder('~/path/to/my/folder').getFiles();
Finally you could use that array in a loop to place all the images into your document.

Universal Image Loader - load from cache if available else load from web causing havoc in grid list

I have a grid list and i use UIL to load images from server. What i need is , if the file already exists in the cache i want to load that from cache otherwise i want to make a web request.
UIL's cache policy only works for a session. Soon after i close the app and start again after some time, it again loads from the web. Even though files are already in cache.
Even if i try my own logic, the whole thing gets messed up. Scrolling up and down causes images to disappear sometimes.
Here is the list row of my adapter - grid pair:
File imageFile = _imageLoader.getDiscCache().get(url);
thumbHolder.setImageResource(R.drawable.ic_launcher);
if (imageFile.exists())
{
String decoded = Uri.decode(Uri.fromFile(imageFile).toString());
_imageLoader.displayImage(decoded, thumbHolder, _options);
}
else
{
_imageLoader.displayImage(url, thumbHolder, _options);
}
My UIL init is like this:
File cacheDir = StorageUtils.getOwnCacheDirectory(this, "composetest");
if(!cacheDir.exists())
cacheDir.mkdirs();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this.getApplicationContext())
.threadPoolSize(3)
.threadPriority(Thread.NORM_PRIORITY)
.tasksProcessingOrder(QueueProcessingType.FIFO)
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))
.memoryCacheSize(2 * 1024 * 1024)
.discCache(new TotalSizeLimitedDiscCache(cacheDir, (30 * 1024 * 1024)))
.discCacheSize(30 * 1024 * 1024)
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.build();
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_launcher)
.showImageForEmptyUri(R.drawable.ic_launcher)
.showImageOnFail(R.drawable.ic_launcher)
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.NONE)
.cacheInMemory(true)
.cacheOnDisc(true)
.build();
localoptions = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_launcher)
.showImageForEmptyUri(R.drawable.ic_launcher)
.showImageOnFail(R.drawable.ic_launcher)
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.NONE)
.cacheInMemory(true)
.build();
imageLoader.init(config);
UIL docs says it picks from cache if file is already loaded. But each time i start the app it loads from web. how can i make it always read cached file if already loaded else request file from web. ??

Image Size in Windows 8 File Picker

How to know the size of the picked image , or how to put a limit for the picked image , like Maximum size for Image is 1 MB , Here is my code
var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
openPicker.FileTypeFilter.Add(".png");
openPicker.FileTypeFilter.Add(".Jpeg");
openPicker.FileTypeFilter.Add(".Jpg");
StorageFile file = await openPicker.PickSingleFileAsync();
Unfortunately there is no way to restrict the size of the picked file in advance.
After the file has been picked, you can call http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.getbasicpropertiesasync.aspx to get its size.

Resources