private string UploadImg() { string path = string.Empty; FileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { var filename = openFileDialog.FileName; var name = openFileDialog.SafeFileName; IFileTransfer fileTransfer = new FileTransferClient(); byte[] imgData; using (var ms = new MemoryStream()) { Image img = Image.FromFile(filename); img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); imgData = ms.ToArray(); } path = fileTransfer.UploadFile(imgData, name); } return(path); }
private static void UploadFileToCurrentChannel(QueryClient queryClient, string sourceFilePath) { // get the channel we're currenlty in uint channelId = new WhoAmICommand().Execute(queryClient).ChannelId; // create a rondom id for the file transfer uint randomClientId = (uint)_randomForFileClientTransferId.Next(1, 10000); // get only the filename FileInfo sourceFileInfo = new FileInfo(sourceFilePath); // initialize the file transfer to get the server file transfer key FtInitUploadCommandResponse ftInitUploadCommandResponse = new FtInitUploadCommand(randomClientId, "/" + sourceFileInfo.Name, channelId, (ulong)sourceFileInfo.Length, true, false).Execute(queryClient); // create the file transfer cleint with the host of the query client and the port we got from the init download response FileTransferClient transferClient = new FileTransferClient(queryClient.Host, ftInitUploadCommandResponse.FileTransferPort ?? 30033); // upload the file synchron transferClient.UploadFile(ftInitUploadCommandResponse.FileTransferKey, (ulong)sourceFileInfo.Length, sourceFileInfo.FullName); }
public void SaveAll() { foreach (EntryBlock entry in spData.Children) { if (entry.isModified) { byte[] encrypted = CryptoLibrary.encrypt28147cfb(currentUser.MasterKey, entry.Source.Serialize()); IFileTransfer clientUpload = new FileTransferClient(); RemoteFileInfo uploadRequestInfo = new RemoteFileInfo(); using (MemoryStream stream = new MemoryStream(encrypted)) { uploadRequestInfo.FileName = entry.Source.FileName; uploadRequestInfo.Length = encrypted.Length; uploadRequestInfo.FileByteStream = stream; clientUpload.UploadFile(uploadRequestInfo); } } } }
private void btnAddImage_Click(object sender, RoutedEventArgs e) { FileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { var filename = openFileDialog.FileName; var name = openFileDialog.SafeFileName; IFileTransfer fileTransfer = new FileTransferClient(); byte[] imgData; using (var ms = new MemoryStream()) { Image img = Image.FromFile(filename); img.Save(ms,System.Drawing.Imaging.ImageFormat.Gif); imgData = ms.ToArray(); } var path = fileTransfer.UploadFile(imgData, name); } }
private void btnAddImage_Click(object sender, RoutedEventArgs e) { FileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { var filename = openFileDialog.FileName; var name = openFileDialog.SafeFileName; IFileTransfer fileTransfer = new FileTransferClient(); byte[] imgData; using (var ms = new MemoryStream()) { Image img = Image.FromFile(filename); img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); imgData = ms.ToArray(); } var path = fileTransfer.UploadFile(imgData, name); } }
private string UploadImg() { string path = string.Empty; FileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { var filename = openFileDialog.FileName; var name = openFileDialog.SafeFileName; IFileTransfer fileTransfer = new FileTransferClient(); byte[] imgData; using (var ms = new MemoryStream()) { Image img = Image.FromFile(filename); img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); imgData = ms.ToArray(); } path = fileTransfer.UploadFile(imgData, name); } return path; }
private void btnAdd_Click(object sender, RoutedEventArgs e) { IFileTransfer proxy = new FileTransferClient(); RemoteFileInfo uploadRequestInfo = new RemoteFileInfo(); Entry entry = new Entry(entrys, "Name", "", ""); byte[] bEntry = entry.Serialize(); string path = proxy.AddNewFile(currentUser.UserName, bEntry); if (path == null || path == "") { return; } entrys.Deserialize(path, bEntry); byte[] encrypted = CryptoLibrary.encrypt28147cfb(currentUser.MasterKey, entry.Serialize()); using (MemoryStream stream = new MemoryStream(encrypted)) { uploadRequestInfo.FileName = path; uploadRequestInfo.Length = encrypted.Length; uploadRequestInfo.FileByteStream = stream; proxy.UploadFile(uploadRequestInfo); } }