示例#1
0
        /// <summary>
        /// Remote upload file
        /// </summary>
        /// <param name="remoteOption">Remote option</param>
        /// <param name="fileOption">File option</param>
        /// <param name="file">Upload file</param>
        /// <param name="parameters">Parameters</param>
        /// <returns>Return the upload result</returns>
        public static async Task <UploadResult> RemoteUploadAsync(RemoteServerOptions remoteOption, UploadFile fileOption, byte[] file, object parameters = null)
        {
            if (fileOption == null)
            {
                throw new ArgumentNullException(nameof(fileOption));
            }
            Dictionary <string, string> parameterDic = null;

            if (parameters != null)
            {
                parameterDic = parameters.ObjectToStringDcitionary();
            }
            return(await RemoteUploadAsync(remoteOption, new List <UploadFile>() { fileOption }, new Dictionary <string, byte[]>() { { "file1", file } }, parameterDic).ConfigureAwait(false));
        }
示例#2
0
        /// <summary>
        /// Remote upload file
        /// </summary>
        /// <param name="remoteOption">Remote option</param>
        /// <param name="fileOptions">File options</param>
        /// <param name="files">Upload files</param>
        /// <param name="parameters">Parameters</param>
        /// <returns>Return the upload result</returns>
        public static async Task <UploadResult> RemoteUploadAsync(RemoteServerOptions remoteOption, List <UploadFile> fileOptions, Dictionary <string, byte[]> files, Dictionary <string, string> parameters = null)
        {
            if (remoteOption == null || string.IsNullOrWhiteSpace(remoteOption.Host))
            {
                throw new ArgumentNullException(nameof(remoteOption));
            }
            if (files.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(files));
            }
            RemoteParameter uploadParameter = new RemoteParameter()
            {
                Files = fileOptions
            };

            parameters ??= new Dictionary <string, string>();
            parameters[RemoteParameter.RequestParameterName] = JsonSerializeHelper.ObjectToJson(uploadParameter);
            string url = remoteOption.GetUploadUrl();

            return(await HttpHelper.PostUploadAsync(url, files, parameters).ConfigureAwait(false));
        }
示例#3
0
 /// <summary>
 /// Remote upload file
 /// </summary>
 /// <param name="remoteOption">remote options</param>
 /// <param name="fileOption">File option</param>
 /// <param name="file">Upload file</param>
 /// <param name="parameters">Parameters</param>
 /// <returns>Return the upload result</returns>
 public static UploadResult RemoteUpload(RemoteServerOptions remoteOption, UploadFile fileOption, byte[] file, object parameters = null)
 {
     return(RemoteUploadAsync(remoteOption, fileOption, file, parameters).Result);
 }
示例#4
0
 /// <summary>
 /// Remote upload file
 /// </summary>
 /// <param name="remoteOption">Remote option</param>
 /// <param name="fileOptions">File options</param>
 /// <param name="files">Upload files</param>
 /// <param name="parameters">Parameters</param>
 /// <returns>Return the upload result</returns>
 public static UploadResult RemoteUpload(RemoteServerOptions remoteOption, List <UploadFile> fileOptions, Dictionary <string, byte[]> files, Dictionary <string, string> parameters = null)
 {
     return(RemoteUploadAsync(remoteOption, fileOptions, files, parameters).Result);
 }