private async void UploadFileAsync(UploadFileInfo fileInfo) { var context = new InstanceContext(this); var ftClient = new FileTransferServiceReference.FileTransferServiceClient(context); channel = ftClient.ChannelFactory.CreateChannel(); await channel.UploadFileAsync(fileInfo); }
public void UploadFileAsync() { var url = "https://domain.com/api/upload"; var filePath = @"d:\_never.txt"; Assert.ThrowsAsync <FileNotFoundException>(() => { return(_fileTransfer.UploadFileAsync(url, filePath)); }); }
async void Upload() { IFileTransferService proxy = fileTransferServiceFactory.CreateChannel(); try { string fileName = "f:\\xxx.mp4"; // get some info about the input file System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); // open input stream using (System.IO.FileStream stream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { using (StreamWithProgress uploadStreamWithProgress = new StreamWithProgress(stream)) { uploadStreamWithProgress.ProgressChanged += uploadStreamWithProgress_ProgressChanged; // start service client // upload file proxy.UploadFileAsync(fileInfo.Name, fileInfo.Length, uploadStreamWithProgress); // close service client } } } catch (FaultException <SessionFault> sf) { string message = sf.Detail.SessionMessage; string opertaion = sf.Detail.SessionOperation; string reson = sf.Detail.SessionReason; } ((IClientChannel)proxy).Close(); }