Welcome Guest Search | Active Topics | Sign In | Register

Posting file size problem Options
moxbet
Posted: Friday, August 21, 2009 11:17:25 AM
Rank: Newbie
Groups: Member

Joined: 8/20/2009
Posts: 6
MaxDataSize is set to be 1000 KB. MaxDataSize is for individual files.
What I need is that total size of uploaded files can't exceed 1000 KB.
How to do that?

I have used FileUploaded event to erase last file from TempFileLocation if that file is exceeding total size of 1000 KB of all files in PostedFiles property.
However, posted file list in control on page doesn't detect that, it shows that erased file. Only after next post is that file removed from list.
My problem is how to remove file from posted file list on page, which is probably in question PostedFiles property, and also I have some label that I want to update because of that.

Hope I was clear.


Code: HTML/ASPX
<EO:CallbackPanel runat="server" id="CallbackPanel1" Triggers="{ControlID:ajup;Parameter:}">
          <EO:AJAXUploader
                    id ="ajup"
                    runat ="server"
                    TempFileLocation ="~/tempajup"
                    MaxFileCount ="3"
                    MaxDataSize ="1000"
                    ProgressBarSkin ="Windows_Vista"
                    PostedFileLabelFormat ="{posted_file_name} - ({posted_file_size_kb} KB)"
                    AutoPostBack ="true"
                    />
</EO:CallbackPanel>
eo_support
Posted: Friday, August 21, 2009 11:33:48 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

MaxDataSize is for total file size for a single upload. It is primarily a security measure and it is not accurate because of encoding overhead.

There is no way to restricts individual file size within a single multiple file upload. You can upload multiple files in a single pass by setting the uploader's Rows to a number greater than 1. For example, allowing user to upload a .gif product picture and a .doc product description at the same time. In that case, user will see multiple file input box, they would then click the browse button for each of them to fill the input boxes, then click upload button once to upload all the files.

For multiple single file upload, you can perform the check when you handle FileUploader’s FileUploaded event. Inside that event you can examine the size of all uploaded files and then if the file size exceeds your total file size, you can display an error to user and ask them to upload again. You will not be able to erase a single file from the list though because the list is built before FileUploaded event is called.

Your best option would be set MaxFileCount to 1 and let them to upload one by one. This way you can have FileUploaded event to be fired every time a new file is uploaded and you can then simply rejects the last one once the size reaches the limits. You may also want to set the uploader’s AutoUpload and AutoPostBack to true when you do that as this will save the user several clicks.

Hope this helps.

Thanks
moxbet
Posted: Friday, August 21, 2009 12:11:39 PM
Rank: Newbie
Groups: Member

Joined: 8/20/2009
Posts: 6
OK, I have one idea.

I have set AutoPostBack to true.

In FileUploaded event I am calculating total size of uploaded files from PostedFiles property and I set MaxDataSize = MaxDataSize - Total size of uploaded files.
Now, that works for next upload attempt, but I have another problem.
Since Delete selected files button doesn't postback MaxDataSize can't be changed to reflect changes in allowed size.
Can you help me about that?
eo_support
Posted: Friday, August 21, 2009 12:36:23 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

MaxDataSize is primarily a security measure. It is meant for you to set a security limits so that your site will not be bombarded by user trying to upload extra large files to your server. It is not meant to precisely control the file you uploaded. MaxDataSize is not precise because it is the size of whole encoded post back package, this would includes http headers, cookies, not to mention the file itself is encoded. So MaxDataSize and file size are totally different. This means you should not use MaxDataSize to control the file size.

Our suggestion is to set MaxDataSize to a fixed value and when you detect total size exceeded your size limits, use other code mechanisms to notify the user, for example, displaying an error message label or simply discard the last uploaded files. You should not fix your eye on MaxDataSize because it is for a totally different purpose.

Thanks!
moxbet
Posted: Friday, August 21, 2009 1:38:32 PM
Rank: Newbie
Groups: Member

Joined: 8/20/2009
Posts: 6
eo_support wrote:
Hi,

MaxDataSize is primarily a security measure. It is meant for you to set a security limits so that your site will not be bombarded by user trying to upload extra large files to your server. It is not meant to precisely control the file you uploaded. MaxDataSize is not precise because it is the size of whole encoded post back package, this would includes http headers, cookies, not to mention the file itself is encoded. So MaxDataSize and file size are totally different. This means you should not use MaxDataSize to control the file size.

Our suggestion is to set MaxDataSize to a fixed value and when you detect total size exceeded your size limits, use other code mechanisms to notify the user, for example, displaying an error message label or simply discard the last uploaded files. You should not fix your eye on MaxDataSize because it is for a totally different purpose.

Thanks!


I agree, I am aware of MaxDataSize purpose.

Well, I have implemented FileUpload event handler so that the file that exceeds total file size is deleted, but I have problem that PostedFiles doesn't render exact list of files afterwards.
I can't solve that problem, except that either I remove PostedFilesPlaceHolder or I implement my own list of files and delete button, but that will be developing ajax uploader twice.
eo_support
Posted: Friday, August 21, 2009 2:10:23 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
moxbet wrote:
I can't solve that problem, except that either I remove PostedFilesPlaceHolder or I implement my own list of files and delete button, but that will be developing ajax uploader twice.


That is probably what you should do and that's definitely not developing AJAX uploader twice. AJAX uploader is MUCH more complicated than keeping a file list. :)

Keeping a file list is relatively easy. For example, you can keep an array of strings with ViewState and then use a DataGrid to displays the array. If you need to keep multiple values per array item, you can create a single string and then concatenates them together with some delimiter such as "|", for example, "abc.gif|120". You would then rebind the DataGrid from your array whenever you change your array. This way you will have full control of everything.

If you still want to "twist" AJAXUploader futher, you can try to use the callback panel to trigger a second callback so that the uploader can update the file list for you. The basic flow is:

1. The page posts back;
2. AJAXUploader builds the file list;
3. FileUpload is fired;
4. You delete the file. However the uploader's file list is NOT updated because the list is built on step 2 and it has no knowlege to refresh the list;
5. The page is updated on the client side and you see the old list;

What you can do is to add an additional roundtrip to this flow so that:

6. The page is posted back to the server again;
7. AJAXUploader builds the file list again. This time it won't include the files deleted;
8. The page is updated on the client side you should see the new list;

You will need to add additional code in step 4 to set a variable indicating that a second round trip is needed. You can then handle the CallbackPanel's Execute event to pass this information to the client side. For example:

Code: C#
protected void CallbackPanel1_Execute(object sender, CallbackEventArgs e)
{
    e.Data = m_bNeedSecondRoundTrip ? "1" : "0";
}


You will then handle the CallbackPanel's ClientSideAfterUpdate event to check this additional data and if you see it as "1", do an additional post back:

Code: HTML/ASPX
<eo:CallbackPanel ClientSideAfterUpdate="after_update" ....>
    ....
</eo:CallbackPanel>


Code: JavaScript
function after_update(callback, data)
{
    if (data == "1")
        setTimeout("eo_Callback('Callback1', 'reload_uploader')", 10);
}


This will call eo_Callback again and causes a second post back. After the second post back you should have the correct file list. However because now you have two post backs, you will see the wrong list briefly (after the first post back) and then the correct file list. If this is not fine for you, then you will have to add extra code to probably hide everything during the first post back (setting style="display:none") and then turn it back on during the second post back.

I personally do not think this is easier than the first approach, especially consider that it is not accurate at all and it introduces an extra post back. The first approach is much cleaner because you are in full control of your files. Uploader uploads the file for you and you manage the file list. It's very clean and straight forward. Anyway, the bottom line is you are asking for something that is not there, so extra code is needed one way or another. However these are the options and you can decide which one to go for.

Thanks
moxbet
Posted: Friday, August 21, 2009 7:43:21 PM
Rank: Newbie
Groups: Member

Joined: 8/20/2009
Posts: 6
Both solutions are acceptable, but I will implement first, my own file list.
It's not a problem, after all, it's more informative thing then functional, but it's needed.

Thanks for help, excellent support.
eo_support
Posted: Friday, August 21, 2009 8:07:51 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Glad to hear that you like our product and service. Please feel free to let us know if you have any other questions.


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.