This is a migrated thread and some comments may be shown as answers.

How to upload more files from one selected file

7 Answers 59 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Son
Top achievements
Rank 1
Son asked on 17 Jun 2011, 08:32 AM
I have a problem with RadUpload..In my case I want to upload one image file to server and generate it into more files. I give example:
I select abc.jpg from opendialog, and I want to generate it into (abc1.jpg ,abc2.jpg, abc3.jpg) and upload to server.After uploading success so I will have 3 files image on server (abc1,abc2,abc3) with same content.
How can I do that.
Please help me.

7 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 22 Jun 2011, 08:24 AM
Hi Son,

I would recommend duplicating the file on the server rather than on the client. You would upload only one file instead of three identical files. Moreover, you have no restrictions to the file system on the server as you have in the Silverlight application.

What you can do is check the IsFinalFileRequest method in the SaveChunkData of the RadUploadHandler. If this is the file file request, the file has been uploaded and you can open it and copy it into other files.

Please let me know if you have further questions on this.

Greetings,
Alex Fidanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Son
Top achievements
Rank 1
answered on 22 Jun 2011, 08:29 AM
Hi Alex
Can you give me the example or code snippet in SaveChunkData method() to open and copy the file to another ?
Is it possible to rename the file on server ?
Thank you so much for your repply
0
Accepted
Alex Fidanov
Telerik team
answered on 22 Jun 2011, 08:36 AM
Hi Son,

You can use something like the code below:

public override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
{
    bool success = base.SaveChunkData(filePath, position, buffer, contentLength, out savedBytes);
    if (this.IsFinalFileRequest() && success)
    {
        string fileName = this.GetFilePath();
        string newFileName = "newFile_" + fileName;
        FileInfo fileInfo = new FileInfo(fileName);
        if (fileInfo.Exists)
        {
            File.Copy(fileName, newFileName);
        }
    }
    return success;
}


Greetings,
Alex Fidanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Son
Top achievements
Rank 1
answered on 22 Jun 2011, 08:49 AM
Hi Alex
Your code works properly as I expected. but there is small problem with the name of new files.
How can I transfer the list parameter of name files to server from client?
Example: string[] nameList = new string[] { "abc1.jpg", "abc2.jpg","background.jpg" };

I have used this.GetQueryParameter("NameList"); but this method just returns string not a list.
Thank you
0
Accepted
Alex Fidanov
Telerik team
answered on 27 Jun 2011, 12:21 PM
Hello Son,

In the FileUploadStarting event you can send the new file names as parameters, like this:

e.FileParameters.Add("NewFileNamePrefixes", "abc1.png, abc2.png, abc3.png, background.png");
On the server, in the SaveChunkData method, you can get this parameter by querying it:
string newFileNamePrefixes = this.GetQueryParameter("NewFileNamePrefixes");
Now you have to split the names by the separators and create a separate file for each name.
string[] newFileNames = newFileNamePrefixes.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
The code for copying the file is almost identical to the one from my previouos code.

Please let me know if you have further questions on this.


All the best,
Alex Fidanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Son
Top achievements
Rank 1
answered on 27 Jun 2011, 12:45 PM
Hi Alex
Thank you very much, your helps has solved my problems.
By the way, I have a small problem which is not possible to do.
I choose one picture file near 1mb to upload and as we discussed about copy into more files. In my case, I copy into 10 files (a1.jpg, a2.jpg.v...v. a10.jpg). How can I make the RadUpload progressbar works correctly with the total times of this process include uploading and copying. That means how can you make the progressbar work correctly with copying file to another site in SaveChunkData method. As I known, progress bar is complete when the SaveChunkData is raised.
0
Alex Fidanov
Telerik team
answered on 29 Jun 2011, 04:15 PM
Hi Son,

Currently, this is something that you will not be able to achieve. The uploading percentage is calculated from the ratio between the uploaded and the total bytes of the file. The processes (such as copying files on the server) are not taken into account.

Greetings,
Alex Fidanov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Upload
Asked by
Son
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Son
Top achievements
Rank 1
Share this question
or