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

How do I get a list of server side files which are uploaded to server side

3 Answers 79 Views
CloudUpload
This is a migrated thread and some comments may be shown as answers.
ADS Development Team
Top achievements
Rank 1
ADS Development Team asked on 14 Jan 2016, 11:37 AM

I am using the method of the Interface

System.Threading.Tasks.Task<object> UploadFileAsync(string fileName, Stream fileStream, CloudUploadFileProgressChanged uploadProgressChanged, CancellationToken cancellationToken)

 

Task<object> which is the reurn type contains each file uploaded but how do I get this as a list which I can then use. This file list is different from what is uploaded bcos the uploaded files have the server side url link where as client files have c:\url

 My code is as below

 

        public Task<object> UploadFileAsync(string fileName, System.IO.Stream fileStream, CloudUploadFileProgressChanged uploadProgressChanged, CancellationToken cancellationToken)
        {
            Func<object> f = () =>
            {
                lock (_object)
                {
                    FileSize = fileStream.Length;
                    
                    if (uploadProgressChanged != null)
                    {
                        UploadProgressChanged = uploadProgressChanged;

                        UploadProgressChanged(FileSize / 10);
                    }
                    if (cancellationToken != CancellationToken.None && cancellationToken.IsCancellationRequested)
                    {
                        return null;
                    }
                    HttpResponseMessage fileResult;
                    CustomFileResult customFileResult;
                    try
                    {
                        fileResult = UploadFile(fileName, fileStream, cancellationToken).Result;
                        if (fileResult.IsSuccessStatusCode)
                        {
                            var response = fileResult.Content.ReadAsStringAsync();
                            customFileResult = JsonConvert.DeserializeObject<CustomFileResult>(response.Result);

                        }
                        else
                        {
                            var message = string.Format("Status code {0}, Reason {1}", fileResult.StatusCode,
                                fileResult.ReasonPhrase);
                            throw new ApplicationException(message);
                        }
                    }
                    catch (System.Exception)
                    {
                        throw;
                    }

                    if (UploadProgressChanged != null)
                    {
                        UploadProgressChanged(FileSize);
                    }

                    return customFileResult;
                }
            };

            fileStream.Position = 0;
            return Task.Factory.StartNew(f, cancellationToken);
        }

 

    public class CustomFileResult
    {
        public IEnumerable<string> FileNames { get; set; }
        public string Description { get; set; }
        public DateTime CreatedTimestamp { get; set; }
        public DateTime UpdatedTimestamp { get; set; }
        public string DownloadLink { get; set; }
        public IEnumerable<string> ContentTypes { get; set; }
        public IEnumerable<string> Names { get; set; }
        public IEnumerable<string> Sizes { get; set; }
    }

 

Can you provide an example where I can get hold of the result of the upload and populate the client side with the server images which are uploaded which in my case is the CustomFileResult and the property is DownloadLink.

3 Answers, 1 is accepted

Sort by
0
Petar Marchev
Telerik team
answered on 19 Jan 2016, 08:55 AM
Hi,

I am a bit unsure what exactly it is that you are in need of. The RadCloudUpload control is essentially a UI control and does not really have any uploading or downloading capabilities. The actual uploading is done by the provider in the UploadFileAsync method. The return type of the async action is object, so you can pass any type of object there, including an info item with data about the uploaded file.

If I am not being clear enough, I will try to explain in little more details here. In your implementation of the UploadFileAsync method, you have declared a Func<object> f that handles the upload process. In this action, there is a call to UploadFile method, that seems to be doing the actual upload. Now, either this method can return the information you need, or it can't. If it returns information about the uploaded file, you seem to be all set. If it doesn't, then the uploading process alone does not seem to give you enough information, so you may need to start a download procedure after the upload in order to obtain the information needed.

With a little guessing from my side, it seems that the fileResult of the UploadFile contains a CustomFileResult object that should contain the exact information that you need. This customFileResult is deserialized and is later returned by the Func<object> f, so from what we see, you already have everything you need.

Let me know if I was unable to address properly you inquiry or if you need any other informaion.

Regards,
Petar Marchev
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
ADS Development Team
Top achievements
Rank 1
answered on 21 Jan 2016, 03:27 PM
Yes I do have the customFileResult but it is how I get that value from this class and get it into my viewmodel is the tricky part. How do I do that?
0
Petar Marchev
Telerik team
answered on 22 Jan 2016, 08:33 AM
I think that the easiest way to go here is to introduce a FileUploaded event in the provider. You can then attach a handler to this event and call the corresponding method in the view model. I have attached a small project that demonstrates this.

I think that if we had a similar event for the RadCloudUpload, things would have been a bit easier. This is why I have created a feature request in our feedback portal. I have updated your Telerik points as a thank you for helping us improve our products.

Let us know if you need anything else.

Regards,
Petar Marchev
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
CloudUpload
Asked by
ADS Development Team
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
ADS Development Team
Top achievements
Rank 1
Share this question
or