Give unique name to each file uploaded

Jul 13, 2011 at 4:11 PM

Dear hyspdrt,

I do enjoy the interlink upload component very much, Thank you.

However, I face a scenario that I have upload multiple files to the server, and meanwhile save the file names (just the name, not file iteself) into the database. To prevent duplication, I will have to give each file an unique name (GUID is a good way of unique name). But I am not too sure about how to get this done.

Solution A:

Generate the GUID as file name on the client side for each file, then I can save the GUID into the DomainContext. But I did not find the right place to hook this GUID to the file itself.

Solution B:

Generate the GUID on the server side. But then I will not know the GUID name and therefore cannot put it into DomainContext.

What is your suggestion? Thanks very much.

Jul 14, 2011 at 3:44 AM

Append:

I understand that there is a callback method to pass metadata from client to server side, however, is the calllback method suitable for the scenario above? For example, if I select 5 files and upload in batch, can the callback pass 5 GUID as file name to the server?

Coordinator
Jul 14, 2011 at 1:39 PM

Yes, the callback is called for each file that the user attempts to upload. So you can pass what ever information you need.

Coordinator
Jul 14, 2011 at 1:41 PM

I recommend providing any client context info in the callback you desire, then in the UploadComplete method (which is after the file has been uploaded to the server) write your record and file path etc. to your database.

Coordinator
Aug 22, 2011 at 11:38 AM

Another thought, now that (with the latest release), you can pass back (from server to client per file) a string value in the UploadComplete server side method, after you save your file you can pass back the File Id (Guid etc.).

so if you create the file db id initially to prevent duplicates, you can write that to a temp file. The base Handler class has a method for creating temporary files. you can access again once the upload completes, and then return the client.

Aug 31, 2011 at 3:30 PM

Many thanks hyspdrt. I didn't expect that you guys are so fast :)

One quick question about the newly added feature - how can we access the returned string on the client side? Listen to an event maybe?

Coordinator
Aug 31, 2011 at 3:37 PM

Yes, there is a new event FileUploaded event with event args of FileUploadCompletedEventArgs that contains the name of the file and result string from the server.

Aug 31, 2011 at 3:41 PM

Your quick reply makes our world shines... Perfect job. Many thanks.

Nov 16, 2011 at 9:15 PM

I'm having trouble figuring out how to call the FileUploaded event client side, is there a code sample for this? Thanks.

Coordinator
Nov 16, 2011 at 9:22 PM

You don't call it. On the server side your return what ever result you want to pass back to the client for a particular file. Then on the client side, you connect to the FileUploaded event handler.

Like so:

var d = new UploadFileDialog();
d.FileUploaded += FileUploadHandler;
d.Show();

// called for each file that is successfully uploaded
void FileUploadHandler(string fileName, string result)
{
    MessageBox.Show(result);
}
Nov 16, 2011 at 10:27 PM

 hmm still can't seem to figure it out, trying to integrate it with the quick start sample and I'm getting this error "No overload for 'FileUploadHandler' matches delegate 'System.EventHandler<HSS.Interlink.FileUploadCompletedEventArgs>'"

private void Button_Click(object sender, RoutedEventArgse)
{
var udialog = new UploadFileDialog();
udialog.FileUploaded += FileUploadHandler;
udialog.Show();
}

// called for each file that is successfully uploaded
void FileUploadHandler(string fileName, string result)
{
MessageBox.Show(result);
}
Coordinator
Nov 16, 2011 at 10:30 PM

Sorry, I tried to short hand it and got it wrong.

Try this...

void SomeMethod()
{
	d = new UploadFileDialog();
	d.FileUploaded += new EventHandler<FileUploadCompletedEventArgs>(d_FileUploaded);
}
void d_FileUploaded(object sender, FileUploadCompletedEventArgs e)
{
	throw new NotImplementedException();
}
Nov 17, 2011 at 2:15 AM

Thanks that works great.

Now Is there a way when uploading multiple files at once that I can tell when all of the uploads have finished?

Thanks again.

Coordinator
Nov 17, 2011 at 2:16 AM

Yes, that is the Completed event. And will fire once all files have been processed.

From: guy_davison [email removed]
Sent: Wednesday, November 16, 2011 7:15 PM
To: Glen Banta
Subject: Re: Give unique name to each file uploaded [interlink:265010]

From: guy_davison

Thanks that works great.

Now Is there a way when uploading multiple files at once that I can tell when all of the uploads have finished?

Thanks again.