示例#1
0
            private async Task <IInputFile> UploadProfilePhoto(Telegram service, TelegramClient client,
                                                               byte[] resizedPhoto)
            {
                var       fileId      = service.GenerateRandomId();
                const int chunkSize   = 65536;
                var       chunk       = new byte[chunkSize];
                uint      chunkNumber = 0;
                var       offset      = 0;

                using (var memoryStream = new MemoryStream(resizedPhoto))
                {
                    int bytesRead;
                    while ((bytesRead = memoryStream.Read(chunk, 0, chunk.Length)) > 0)
                    {
                        //RPC call
                        var uploaded =
                            await client.Methods.UploadSaveFilePartAsync(new UploadSaveFilePartArgs
                        {
                            Bytes    = chunk,
                            FileId   = fileId,
                            FilePart = chunkNumber
                        });

                        if (!uploaded)
                        {
                            return(null);
                        }
                        chunkNumber++;
                        offset += bytesRead;
                    }

                    return(new InputFile
                    {
                        Id = fileId,
                        Md5Checksum = "",
                        Name = service.GenerateRandomId() + ".jpeg",
                        Parts = chunkNumber
                    });
                }
            }