コード例 #1
0
        public async void UploadFile(string filePath, UploadFileType uploadFileType, IUploadCallback uploadCallback)
        {
            FileStream fileStream = null;

            try
            {
                await Task.Run(() => { fileStream = File.Open(filePath, FileMode.Open); });

                var fileName = Path.GetFileName(filePath);

                var uploadTask = storageClient.Child(uploadFileType.ToString()).Child(fileName).PutAsync(fileStream);
                uploadTask.Progress.ProgressChanged += (s, e) => uploadCallback.SetUploadPercentage(e.Percentage);

                var downloadLink = await uploadTask;

                InsertUploadInfo(new UploadInfo {
                    Type = uploadFileType.ToString(), DownloadLink = downloadLink
                });

                uploadCallback.UploadCompleted();
            }
            catch (Exception ex)
            {
                uploadCallback.SetUploadPercentage(-1);
            }
        }
コード例 #2
0
        /**
         * append file to storage server (by callback)
         *
         * @param appender_file_id the appender file id
         * @param file_size        the file size
         * @param callback         the write data callback object
         * @return 0 for success, != 0 for error (error no)
         */
        public int append_file1(String appender_file_id, long file_size, IUploadCallback callback)
        {
            String[] parts = new String[2];
            this.errno = split_file_id(appender_file_id, parts);
            if (this.errno != 0)
            {
                return(this.errno);
            }

            return(this.append_file(parts[0], parts[1], file_size, callback));
        }
コード例 #3
0
        /**
         * upload appender file to storage server (by callback)
         *
         * @param group_name    the group name to upload file to, can be empty
         * @param file_size     the file size
         * @param callback      the write data callback object
         * @param file_ext_name file ext name, do not include dot(.)
         * @param meta_list     meta info array
         * @return file id(including group name and filename) if success, <br>
         * return null if fail
         */
        public String upload_appender_file1(String group_name, long file_size,
                                            IUploadCallback callback, String file_ext_name,
                                            NameValueCollection meta_list)
        {
            var parts = this.upload_appender_file(group_name, file_size, callback, file_ext_name, meta_list);

            if (parts != null)
            {
                return(parts[0] + SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + parts[1]);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
        /**
         * upload file to storage server (by callback)
         *
         * @param master_file_id the master file id to generate the slave file
         * @param prefix_name    the prefix name to generate the slave file
         * @param file_size      the file size
         * @param callback       the write data callback object
         * @param file_ext_name  file ext name, do not include dot(.)
         * @param meta_list      meta info array
         * @return file id(including group name and filename) if success, <br>
         * return null if fail
         */
        public String upload_file1(String master_file_id, String prefix_name, long file_size,
                                   IUploadCallback callback, String file_ext_name,
                                   NameValueCollection meta_list)
        {
            String[] parts = new String[2];
            this.errno = split_file_id(master_file_id, parts);
            if (this.errno != 0)
            {
                return(null);
            }

            parts = this.upload_file(parts[0], parts[1], prefix_name, file_size, callback, file_ext_name, meta_list);
            if (parts != null)
            {
                return(parts[0] + SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + parts[1]);
            }
            else
            {
                return(null);
            }
        }