CreateUploadAsync() приватный Метод

private CreateUploadAsync ( [ uri, [ parts ) : IAsyncOperation
uri [
parts [
Результат IAsyncOperation
Пример #1
0
        private static async Task<UploadOperation> CreateUploadOperationForCreateVideo(
            IStorageFile file, string token, BackgroundUploader uploader)
        {
            const string boundary = "videoboundary";

            List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();

            BackgroundTransferContentPart metadataPart = new BackgroundTransferContentPart("token");

            metadataPart.SetText(token);
            //metadataPart.SetText("iamatoken");
            parts.Add(metadataPart);

            BackgroundTransferContentPart videoPart = new BackgroundTransferContentPart("content_file", file.Name);
            videoPart.SetFile(file);
            videoPart.SetHeader("Content-Type", file.ContentType);
            parts.Add(videoPart);

            return
                await uploader.CreateUploadAsync(
                    new Uri(AddVideoPostUri),
                    parts,
                    "form-data",
                    boundary);
        }
        private async void UploadMultipleFiles(Uri uri, IReadOnlyList<StorageFile> files)
        {
            if (files.Count == 0)
            {
                rootPage.NotifyUser("No file selected.", NotifyType.ErrorMessage);
                return;
            }

            ulong totalFileSize = 0;
            for (int i = 0; i < files.Count; i++)
            {
                BasicProperties properties = await files[i].GetBasicPropertiesAsync();
                totalFileSize += properties.Size;

                if (totalFileSize > maxUploadFileSize)
                {
                    rootPage.NotifyUser(String.Format(CultureInfo.CurrentCulture,
                        "Size of selected files exceeds max. upload file size ({0} MB).", 
                        maxUploadFileSize / (1024 * 1024)), NotifyType.ErrorMessage);
                    return;
                }
            }

            List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();
            for (int i = 0; i < files.Count; i++)
            {
                BackgroundTransferContentPart part = new BackgroundTransferContentPart("File" + i, files[i].Name);
                part.SetFile(files[i]);
                parts.Add(part);
            }

            BackgroundUploader uploader = new BackgroundUploader();
            UploadOperation upload = await uploader.CreateUploadAsync(uri, parts);

            String fileNames = files[0].Name;
            for (int i = 1; i < files.Count; i++)
            {
                fileNames += ", " + files[i].Name;
            }

            Log(String.Format(CultureInfo.CurrentCulture, "Uploading {0} to {1}, {2}", fileNames, uri.AbsoluteUri, 
                upload.Guid));

            // Attach progress and completion handlers.
            await HandleUploadAsync(upload, true);
        }
Пример #3
0
        private async void StartMultipartUpload_Click(object sender, RoutedEventArgs e)
        {
            // By default 'serverAddressField' is disabled and URI validation is not required. When enabling the text
            // box validating the URI is required since it was received from an untrusted source (user input).
            // The URI is validated by calling Uri.TryCreate() that will return 'false' for strings that are not valid URIs.
            // Note that when enabling the text box users may provide URIs to machines on the intrAnet that require
            // the "Home or Work Networking" capability.
            Uri uri;
            if (!Uri.TryCreate(serverAddressField.Text.Trim(), UriKind.Absolute, out uri))
            {
                rootPage.NotifyUser("Invalid URI.", NotifyType.ErrorMessage);
                return;
            }

            FileOpenPicker picker = new FileOpenPicker();
            picker.FileTypeFilter.Add("*");
            IReadOnlyList<StorageFile> files = await picker.PickMultipleFilesAsync();

            if (files.Count == 0)
            {
                rootPage.NotifyUser("No file selected.", NotifyType.ErrorMessage);
                return;
            }

            ulong totalFileSize = 0;
            for (int i = 0; i < files.Count; i++)
            {
                BasicProperties properties = await files[i].GetBasicPropertiesAsync();
                totalFileSize += properties.Size;

                if (totalFileSize > maxUploadFileSize)
                {
                    rootPage.NotifyUser(String.Format(CultureInfo.CurrentCulture,
                        "Size of selected files exceeds max. upload file size ({0} MB).", 
                        maxUploadFileSize / (1024 * 1024)), NotifyType.ErrorMessage);
                    return;
                }
            }

            List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();
            for (int i = 0; i < files.Count; i++)
            {
                BackgroundTransferContentPart part = new BackgroundTransferContentPart("File" + i, files[i].Name);
                part.SetFile(files[i]);
                parts.Add(part);
            }

            BackgroundUploader uploader = new BackgroundUploader();
            UploadOperation upload = await uploader.CreateUploadAsync(uri, parts);

            String fileNames = files[0].Name;
            for (int i = 1; i < files.Count; i++)
            {
                fileNames += ", " + files[i].Name;
            }

            Log(String.Format(CultureInfo.CurrentCulture, "Uploading {0} to {1}, {2}", fileNames, uri.AbsoluteUri, 
                upload.Guid));

            // Attach progress and completion handlers.
            await HandleUploadAsync(upload, true);
        }
Пример #4
0
        private static async Task<UploadOperation> CreateUploadOperationForCreateImage(
            IStorageFile file, string token, BackgroundUploader uploader)
        {
            const string boundary = "imgboundary";

            List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();

            BackgroundTransferContentPart metadataPart = new BackgroundTransferContentPart("token");

            metadataPart.SetText(token);
            //metadataPart.SetText("iamatoken");
            parts.Add(metadataPart);

            BackgroundTransferContentPart imagePart = new BackgroundTransferContentPart("photo", file.Name);
            imagePart.SetFile(file);
            imagePart.SetHeader("Content-Type", file.ContentType);
            parts.Add(imagePart);

            return
                await uploader.CreateUploadAsync(
                    new Uri(HttpFotosSapoPtUploadpostHtmlUri),
                    parts,
                    "form-data",
                    boundary);
        }
       // private const string bucketurl = "http://s3.amazonaws.com/";

       // private const string bucketurl = "com.mf.carl-prototype.s3.amazonaws.com";
        #region Upload
        public async Task UploadFile(IReadOnlyList<StorageFile> files)
        {
            try
            {
               

                basicAwsCredentials = new BasicAWSCredentials(accesskey, secretkey);
                List<BackgroundTransferContentPart> parts = new List<BackgroundTransferContentPart>();
                for (int i = 0; i < files.Count; i++)
                {
                    BackgroundTransferContentPart part = new BackgroundTransferContentPart(files[i].Name, files[i].Name);
                    this.Filename = files[i].Name;
                    part.SetFile(files[i]);
                    parts.Add(part);
                }
                //Uri uri = new Uri(bucketurl + ExistingBucketName + "/");
                //Uri uri = new Uri("https://com.mf.carl-prototype.s3-us-west-2.amazonaws.com/");
                Uri uri = new Uri("https://s3.amazonaws.com/" + ExistingBucketName +"/");
              //  Uri uri = new Uri("https://"+ExistingBucketName+".s3-us-west-2.amazonaws.com/" );
            
                BackgroundUploader uploader = new BackgroundUploader();

                PasswordCredential pwdCredential = new PasswordCredential();
                pwdCredential.UserName = accesskey;
                pwdCredential.Password = secretkey;
                uploader.ServerCredential = pwdCredential;
               // uploader.Method = "POST";
       
               // uploader.SetRequestHeader("Content-Type", "multipart/form-data;boundary=34");
                  uploader.ServerCredential = new PasswordCredential{ UserName=accesskey, Password= secretkey};
                UploadOperation upload = await uploader.CreateUploadAsync(uri, parts);
                // Attach progress and completion handlers.
                await HandleUploadAsync(upload, true);
            }
            catch(Exception ex)
            {

            }
        }
Пример #6
0
        /// <summary>
        /// Invoked when image add button is clicked and choose the image.
        /// </summary>
        /// <param name="sender">The image add button clicked.</param>
        /// <param name="e">Event data that describes how the click was initiated.</param>
        private async void ImageUploadButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = FileTypePicker(imagesFilterTypeList);
            if (picker == null) return;

            images = await picker.PickMultipleFilesAsync();
            if (images == null || images.Count == 0) return;

            Image imgImg = new Image
            {
                Source = new BitmapImage(new Uri("ms-appx:///Images/Upload/image.png")),
                Margin = new Thickness(5, 0, 5, 0)
            };

            ToolTip toolTip = new ToolTip();
            toolTip.Content = images[0].Name;
            ToolTipService.SetToolTip(imgImg, toolTip);

            totalImagePanel.Children.RemoveAt(totalImagePanel.Children.Count - 1);
            imagePanel.Children.Add(imgImg);

            List<BackgroundTransferContentPart> imageParts = CreateBackgroundTransferContentPartList(images);

            Uri uploadUri = new Uri(Constants.DataCenterURI + "Upload.aspx?username="******"Image uplaod error3. Please check your network.");
            }
        }
Пример #7
0
        /// <summary>
        /// Invoked when upload button in popup is clicked and add new lesson.
        /// </summary>
        /// <param name="sender">The upload button clicked.</param>
        /// <param name="e">Event data that describes how the click was initiated.</param>
        private async void UploadLessionButton_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckLessonInfomation())
            {
                ShowMessageDialog("Format error1! Please check your upload infomation.");
                return;
            }
            lessonUploadProgressRing.IsActive = true;
            UploadLessionButton.Visibility = Visibility.Collapsed;
            CancelUploadButton.Visibility = Visibility.Collapsed;
            allLessons.Add(new Lesson(++lessonCount, lessonName.Text, lessonDescription.Text));

            List<BackgroundTransferContentPart> docParts = CreateBackgroundTransferContentPartList(docs);
            List<BackgroundTransferContentPart> audioParts = CreateBackgroundTransferContentPartList(audios);
            List<BackgroundTransferContentPart> videoParts = CreateBackgroundTransferContentPartList(videos);

            List<BackgroundTransferContentPart> allParts = new List<BackgroundTransferContentPart>();
            if (docParts != null) allParts.AddRange(docParts);
            if (audioParts != null) allParts.AddRange(audioParts);
            if (videoParts != null) allParts.AddRange(videoParts);

            Uri uploadUri = new Uri(Constants.DataCenterURI + "Upload.aspx?username="******"Network connection error2!");
                lessonCount--;
                ResetPopup();
                return;
            }

            AddLessonInfo();
            lessonScrollView.ScrollToVerticalOffset(lessonScrollView.VerticalOffset);
            lessonUploadProgressRing.IsActive = false;
            UploadLessionButton.Visibility = Visibility.Visible;
            CancelUploadButton.Visibility = Visibility.Visible;
            wholeFrame.Opacity = 1;
            addLessonPopup.IsOpen = false;
        }