Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
daveg  
#1 Posted : Wednesday, May 7, 2008 10:26:08 PM(UTC)
daveg

Rank: Member

Groups: Member
Joined: 2/24/2008(UTC)
Posts: 19

Hey,

I am having a problem to do with monitoring whether the upload completes successfully or not. I have been using the following code to control what action and redirect pages are used:

Code:
iu.addParam("Action", "http://domain.com/action.php?var1=1&var2=2");
iu.addParam("RedirectUrl", "http://domain.com");

I assumed the action page was only loaded (like the redirect page) on a successfully completed upload, but this does not appear to be so, so when a user starts uploading then cancels or it errors the action script will still be run. This would be fine, but i can't seem to find a variable that is acccessible by the action script that defines whether the upload completed successfully, is there one? If not, the alternative appears to be to use the following code in place of the addParam action option above:

Code:

<script type="text/javascript">
function ImageUploader_Progress(Status, Progress, ValueMax, Value, StatusText)
{
    if (Status=="COMPLETE"){
        //We redirect to galery.aspx page when upload process is completed
        window.location = "action.php";
    }
}
</script>
.....
iu.addEventListener("Progress", "ImageUploader_Progress");

Presumably this would then ensure that action.php was only run on successful completion of an upload? This would be great, however i can't work out how to pass custom variables into this function? My action script needs a large number of other variables to function correctly (hence the ?var1=1&var2=2 in the action param). One would assume using the second method one would need something like the following code, which would presumbly give me access to the added fields from action.php:

Code:

<script type="text/javascript">
function ImageUploaderID_BeforeUpload() {
  getImageUploader("ImageUploader1").AddField("var1", "");
  getImageUploader("ImageUploader1").AddField("var2", "");
}
</script>
...
iu.addEventListener("BeforeUpload", "ImageUploaderID_BeforeUpload");

The problem now is how do i get the variable values for var1 and var2 into the addfield arguments within the javascript function? Can i add custom variables to the ImageUploaderID_BeforeUpload function so i can add varibles at the addeventlistener stage or is there another way to do it?

Thanks so much, i very much look forward to hearing from you!

Dave

Eugene Kosmin  
#2 Posted : Sunday, May 11, 2008 1:56:15 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Hello Dave,

Quote:

I assumed the action page was only loaded (like the redirect page) on a successfully completed upload, but this does not appear to be so, so when a user starts uploading then cancels or it errors the action script will still be run

No, Action property is the URL where Image Uploader sends POST request. With successful upload you will be redirected to the URL from RedirectUrl property.

Code:
<script type="text/javascript">
function ImageUploader_Progress(Status, Progress, ValueMax, Value, StatusText)
{
    if (Status=="COMPLETE"){
        window.location = "RedirectUrl.php";
    }
}
</script>
.....
iu.addEventListener("Progress", "ImageUploader_Progress");

This code could replace only RedirectUrl property. No an action. Image Uploader sends data to action URL and gets a response from it. Upload is successful only when the response from action is OK.

Quote:
Can i add custom variables to the ImageUploaderID_BeforeUpload function

You can try this:

Code:
var _varValue1 = "value1",
    _varValue2 = 123;
	

function ImageUploaderID_BeforeUpload()
{
	getImageUploader("ImageUploader").AddField("var1", _varValue1);
	getImageUploader("ImageUploader").AddField("var2", _varValue2);
	return true;
}

Best regards,

Eugene Kosmin

The Aurigma Development Team

daveg  
#3 Posted : Wednesday, May 28, 2008 6:17:36 AM(UTC)
daveg

Rank: Member

Groups: Member
Joined: 2/24/2008(UTC)
Posts: 19

Thanks, but sadly that does not solve my problem. The redirecturl is fine, the problem is with the action URL.

How does the action script know whether the upload was successful? So a user is uploading 10 pictures lets say and he clicks cancel after picture 5. It then runs the actionURL, even though the user clicked cancel. I have it set to only run the relevant actions if move_uploaded_file is successful, so in this case the first five pictures would be successful and so it would add those five to their gallery and not the remaining ones.

Assuming if a user presses cancel they want to cancel the whole upload and not upload any pictures then how do you do that in the actionscript as there doesn't appear to be any variables to define whether it completed successfully/was cancelled etc?

I would really appreciate some help on this, thanks,

Dave

Eugene Kosmin  
#4 Posted : Wednesday, May 28, 2008 3:19:57 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Hello,

Action URL handles upload content, so it can not know whether upload was successful. The upload will be successful if Action script will handle it without errors.

Maybe you should try to use FilesPerOnePackageCount property for uploading files one by one:

Code:
<script language="javascript">
var iu = new ImageUploaderWriter("ImageUploader", 800, 500);
//...other params...
iu.addParam("FilesPerOnePackageCount", "1");
//...other params...
iu.writeHtml();
</script>

In this case already uploaded files will be saved after user cancelation of uploading process.

Best regards,

Eugene Kosmin

The Aurigma Development Team

daveg  
#5 Posted : Thursday, May 29, 2008 8:21:36 PM(UTC)
daveg

Rank: Member

Groups: Member
Joined: 2/24/2008(UTC)
Posts: 19

Ok, i thought that if you pressed cancel then there should be a way to prevent any files being uploaded, but that's not a big problem. I think i understand the logic more now.

I have added the FilesPerOnePackageCount and related methods to allow for single file uploads so i can enable the resume feature, which appears to be working fine. This should hopefully solve some of my users problems. I now have one issue remaining:

At the end of successful upload (as well as obviously moving the uploaded files to their correct locations) i create a number of picture banners and related gallery images which involve a number of php functions using GD. This only needs to be done once after all the pictures have been uploaded so having it in the actionscript is not a good idea as it will then run after every single picture.

The only alternative is to somehow run these php functions from within the ImageUploader_Progress or afterupload functions, the problem with this obviously being that i can't run php scripts transparently from within javascript.

So my question is:

Assuming i am uploading one file at a time to allow for resuming, how do i run a php script, after the upload has finished, that will definitely run irrelevant of whether it errors/is cancelled or completes successfully, without putting it into the actionscript and making it run after every single picture is uploaded?

thanks very much,

Dave

Eugene Kosmin  
#6 Posted : Sunday, June 1, 2008 12:15:51 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
You can determine in action script whether the uploaded file is the last one. There are PackageIndex and PackageCount fields in Image Uploader POST, so you can do something like that:

Code:
$packageIndex = $_POST ["PackageIndex"];
$packageCount = $_POST ["PackageCount"];

if ($packageIndex == $packageCount - 1)
{
	// Actions after last picture uploaded
}
Best regards,

Eugene Kosmin

The Aurigma Development Team

daveg  
#7 Posted : Sunday, June 1, 2008 9:20:31 PM(UTC)
daveg

Rank: Member

Groups: Member
Joined: 2/24/2008(UTC)
Posts: 19

That means that when all the files are successfully uploaded certain actions can be taken, but if a user cancels the upload, or it errors then the last file will never be reached so those final actions would never occur.

Is there an alternative or additional way that would allow actions to be run at the end irrelevant of whether it errored or was cancelled?

Thanks,

Dave

Eugene Kosmin  
#8 Posted : Monday, June 2, 2008 11:36:29 AM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
No, action script is run only after successful upload. Image Uploader does not send data to action script with errors.

BTW, you can use ImageUploader.Error Event for error handing.

Best regards,

Eugene Kosmin

The Aurigma Development Team

daveg  
#9 Posted : Monday, June 2, 2008 6:46:37 PM(UTC)
daveg

Rank: Member

Groups: Member
Joined: 2/24/2008(UTC)
Posts: 19

Exactly, so doing it this way would mean it only runs when it succcessfully uploads all the files that were originally being uploaded.

As i say i need to run a script at the end of the upload, whether that's a successful completion/cancel/error?

Using the ImageUploader.Error poses the same problem as i can't call php functions from within Javascript.

Is there any way of running something at the end of uploading, when successful/errorred or cancelled, (without having to physically redirect the user away from the upload page after error/cancellation)?

I would really appreciate some help on this,

Thanks,

Dave

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.