public async Task <ResultSuccess> UploadFile(string UploadURL, string File, string FileType, UploadFileCompleted OnUploadFileCompleted, UploadProgressChanged OnUploadProgressChanged) { try { UploadFileCompleted_EventHandler = OnUploadFileCompleted; UploadProgressChanged_EventHandler = OnUploadProgressChanged; System.Net.WebClient client = new WebClient(); client.UploadProgressChanged += Client_UploadProgressChanged; client.UploadFileCompleted += Client_UploadFileCompleted; client.Headers["Authorization"] = "Basic "; //client.Headers.Add("Content-Type", FileType); await client.UploadFileTaskAsync(UploadURL, "POST", File); client.UploadProgressChanged -= Client_UploadProgressChanged; client.UploadFileCompleted -= Client_UploadFileCompleted; return(new ResultSuccess()); } catch (Exception err) { return(new ResultSuccess(false, err.ProperMessage())); } }
private ProgressableStreamContent GetMultipartFormDataContent(string contentId, IEnumerable <byte[]> binaries) { var multiPartContent = new MultipartFormDataContent(); int i = 0; foreach (var binary in binaries) { var byteArrayContent = new ByteArrayContent(binary); byteArrayContent.Headers.Add("Content-Type", "application/octet-stream"); multiPartContent.Add(byteArrayContent, contentId, i.ToString(CultureInfo.InvariantCulture)); } var progressableContent = new ProgressableStreamContent(multiPartContent, (current, total) => { UploadProgressChanged?.Invoke(current, total); }); return(progressableContent); }
public void RegisterUploadProgressCallback(UploadProgressChanged callback) { this.m_uploadProgressChangedCallback += callback; }