protected override async Task <HttpTransfer> CreateUpload(HttpTransferRequest request) { if (request.HttpMethod != System.Net.Http.HttpMethod.Post && request.HttpMethod != System.Net.Http.HttpMethod.Put) { throw new ArgumentException($"Invalid Upload HTTP Verb {request.HttpMethod} - only PUT or POST are valid"); } var boundary = Guid.NewGuid().ToString("N"); var native = request.ToNative(); native["Content-Type"] = $"multipart/form-data; boundary={boundary}"; var tempPath = platform.GetUploadTempFilePath(request); this.logger.LogInformation("Writing temp form data body to " + tempPath); using (var fs = new FileStream(tempPath, FileMode.Create)) { if (!request.PostData.IsEmpty()) { fs.Write("--" + boundary); fs.Write($"Content-Type: text/plain; charset=utf-8"); fs.Write("Content-Disposition: form-data;"); fs.WriteLine(); fs.Write(request.PostData !); fs.WriteLine(); } } using (var fs = new FileStream(tempPath, FileMode.Append)) { using (var uploadFile = request.LocalFile.OpenRead()) { fs.Write("--" + boundary); fs.Write($"Content-Type: application/octet-stream"); fs.Write($"Content-Disposition: form-data; name=\"blob\"; filename=\"{request.LocalFile.Name}\""); fs.WriteLine(); await uploadFile.CopyToAsync(fs); fs.WriteLine(); fs.Write($"--{boundary}--"); } } this.logger.LogInformation("Form body written"); var tempFileUrl = NSUrl.CreateFileUrl(tempPath, null); var task = this.Session.CreateUploadTask(native, tempFileUrl); var taskId = TaskIdentifier.Create(request.LocalFile); task.TaskDescription = taskId.ToString(); var transfer = task.FromNative(); task.Resume(); return(transfer); }
protected override Task <HttpTransfer> CreateUpload(HttpTransferRequest request) { var task = this.Session.CreateUploadTask(request.ToNative()); var taskId = TaskIdentifier.Create(request.LocalFile); task.TaskDescription = taskId.ToString(); var transfer = task.FromNative(); task.Resume(); return(Task.FromResult(transfer)); }
protected override Task <HttpTransfer> CreateDownload(HttpTransferRequest request) { var task = this.Session.CreateDownloadTask(request.ToNative()); var taskId = TaskIdentifier.Create(request.LocalFile); task.TaskDescription = taskId.ToString(); //task.Response.SuggestedFilename //task.Response.ExpectedContentLength var transfer = task.FromNative(); task.Resume(); return(Task.FromResult(transfer)); }