|
|
Rank: Member Groups: Member
Joined: 6/27/2004 Posts: 11 Points: 0
|
I would like to implement the removal of some images from the upload list before uploading. Basically, before uploading, I would like to go through the dimensions of each image, and remove the images that do not satisfy certain criteria. I'm able to access the properties of each image via UploadItems, but I fail to remove any of them with the Remove() method as documented. If I did so, IE6 will crash. :'(
Does anybody has any luck doing this successfully? The built-in checking like MinImageWidth, MaxImageHeight are not sufficient for our purpose.
|
|
 Rank: Advanced Member Groups: Administration
, Member
Joined: 7/28/2003 Posts: 1,254 Points: -345 Location: WA, US
|
Hello,
Could you post your code which cause IE craching? I just checked again Remove method and it works perfectly.
Best regards, Fedor Skvortsov
|
|
 Rank: Advanced Member Groups: Member
Joined: 8/3/2003 Posts: 996 Points: 1
|
Hi,
When the BeforeUpload and Progress event are fired all items to be uploaded are already in the Upload list. You can't remove them in this moment.
We will fix the problem with IE crash, but it wouldn't fix your problem.
As a decision we recommend you to use UploadFileCountChange event to remove "bad" items from the Upload list right after adding them.
Sincerely yours, Alex Makhov
|
|
Rank: Member Groups: Member
Joined: 6/27/2004 Posts: 11 Points: 0
|
Hi, Thanks for the reply. I just found what would trigger the bug: if the Layout is TwoPanes then IE will crash once I've done one or two operations Removal(). Conceptually, Removal() should deselect an image, but in TwoPanes layout it will (incorrectly) remove the image from the right panel. Or, is there any function that is able to deselect an image in TwoPanes layout? Here's the HTML code used in the testing: Code:<html> <head></head> <body>
<object type="application/x-oleobject" id="ImageUploader" name="ImageUploader" classid="clsid:A18962F6-E6ED-40B1-97C9-1FB36F38BFA8" CodeBase="/ImageUploader3.cab#version=3,5,46,0" width="600" height="350"> <param name="Action" value="/dev.php"> <param name="Layout" value="TwoPanes"> </object>
<script for="ImageUploader" event="UploadFileCountChange()"> for (i=ImageUploader.UploadItems.Count; i>=1; i--) { var uploadItem = ImageUploader.UploadItems.Item(i); if (uploadItem.Width < 500) { alert(uploadItem.FileName + ': width has to be >= 500'); ImageUploader.UploadItems.Remove(i); } } </script>
</body> </html>
======================================================== 02/14/2008, Fedor This code snippet is out of date.
See the sample bellow for actual code. ========================================================
|
|
 Rank: Advanced Member Groups: Administration
, Member
Joined: 7/28/2003 Posts: 1,254 Points: -345 Location: WA, US
|
We confirm the problem. It will be fixed in next service release. If you want to receive update before next official service release, then please submit case.
Best regards, Fedor Skvortsov
|
|
 Rank: Advanced Member Groups: Member
Joined: 8/3/2003 Posts: 996 Points: 1
|
Hi, The issue with wrong Remove method is resolved and will be available in next ImageUploader release. As about your sample. I think, it needs a little modification: Code:
<script for="ImageUploader" event="UploadFileCountChange()">
for (i=ImageUploader.UploadItems.Count; i>=1; i--) {
var uploadItem = ImageUploader.UploadItems.Item(i);
if (uploadItem.Width < 500) {
alert(uploadItem.FileName + ': width has to be >= 500');
ImageUploader.UploadItems.Remove(i);
i--;
}
}
</script>
======================================================== 02/14/2008, Fedor This topic is out of date.
You should use iuembed.js syntax now. Also please note that you should use plain upload item API (UploadFileXXX methods) instead of UploadItems property.Code:
<script type="text/javascript" src="iuembed.js"></script>
<script type="text/javascript">
function ImageUploaderID_UploadFileCountChange() {
var upl = getImageUploader("ImageUploaderID");
for (var i = upl.getUploadFileCount(); i >= 1; i--) {
if (upl.getUploadFileWidth(i) < 500) {
alert(upl.getUploadFileName(i) + ': width has to be >= 500');
upl.UploadFileRemove(i);
i--;
}
}
}
var iu = new ImageUploaderWriter("ImageUploaderID", 610, 500);
iu.addEventListener("UploadFileCountChange", "ImageUploaderID_UploadFileCountChange");
iu.writeHtml();
</script>
========================================================
Sincerely yours, Alex Makhov
|
|
 Rank: Advanced Member Groups: Administration
, Member
Joined: 7/28/2003 Posts: 1,254 Points: -345 Location: WA, US
|
Hi,
I have sent you update with bug fix.
Best regards, Fedor Skvortsov
|
|
Rank: Member Groups: Member
Joined: 6/27/2004 Posts: 11 Points: 0
|
Thanks for the efficient work! I have downloaded & tested the fixed version. It works perfectly. By the way, Alex has suggested some fix to avoid double checks. I've considred the performance issue during coding. I observe the following properties of the UploadFileCountChange() event: 1) The uploaded file will be included into the upload list one by one (internally), and the event will be fired for each file. Say, you've selected 6 files (not yet checked), and you click a tickbox to check all 6 files. In this case, the event will be fired for 6 times (each for every file added) instead of once (once for all 6 files). 2) The new file added can sit at any position in the UploadItems property, depending on the sequence the files were selected. Based on this I've modified the code as follows: Code:<script for="ImageUploader" event="UploadFileCountChange()"> for (var i=1; i<=ImageUploader.UploadItems.Count; i++) { var uploadItem = ImageUploader.UploadItems.Item(i); if (uploadItem.Width < 500) { alert(uploadItem.FileName + ': width has to be >= 500'); ImageUploader.UploadItems.Remove(i); break; } } </script>
I can safely put a 'break' (instead of 'i--;' or leaving it empty) there because the event will be fired again for the next file. So 'break' should typically be able save more time than using 'i--'. Since the newly added file can be in any position in the UploadItems, we need to use a for() loop to iterate all the files in the upload list just to have a check on the newly added file. This bring up a performance issue. Suppose that I want to select 100 images. In the worst case, all images are accepted, and in this case the for() loop will be iterated for 1+2+3+...+100=5050 times! In the best case, all images are rejected, and the iteration runs for 1+1+1+...+1=100 times. Is there any way I can reduce the iteration time with the current ImageUploader interface?
|
|
 Rank: Advanced Member Groups: Member
Joined: 8/3/2003 Posts: 996 Points: 1
|
Hi,
I can safely put a 'break' (instead of 'i--;' or leaving it empty) there because the event will be fired again for the next file
Yes, you are right in your case. But UploadFileCountChange event doesn't always fired for each item. For example in three panes mode when user drags files to upload pane UploadFileCountChange event is fired only once. You have to take it into account while making UploadFileCountChange event handlers.
Sincerely yours, Alex Makhov
|
|
|
Guest |