How to upload more files from one selected file

8 posts, 2 answers
  1. Son
    Son avatar
    22 posts
    Member since:
    Jun 2011

    Posted 17 Jun 2011 Link to this post

    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.
  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 22 Jun 2011 Link to this post

    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
  3. DevCraft banner
  4. Son
    Son avatar
    22 posts
    Member since:
    Jun 2011

    Posted 22 Jun 2011 Link to this post

    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
  5. Answer
    Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 22 Jun 2011 Link to this post

    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
  6. Son
    Son avatar
    22 posts
    Member since:
    Jun 2011

    Posted 22 Jun 2011 Link to this post

    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
  7. Answer
    Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 27 Jun 2011 Link to this post

    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
  8. Son
    Son avatar
    22 posts
    Member since:
    Jun 2011

    Posted 27 Jun 2011 Link to this post

    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.
  9. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 29 Jun 2011 Link to this post

    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
Back to Top
DevCraft banner