예제 #1
0
        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()));
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 public void RegisterUploadProgressCallback(UploadProgressChanged callback)
 {
     this.m_uploadProgressChangedCallback += callback;
 }