Пример #1
0
        public void AddApiFileParameter(Dictionary <string, object> multipartData, string filePath)
        {
            var count = 0;
            var paths = (filePath.Contains(";") ? filePath.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList() : new List <string> {
                filePath
            });

            foreach (var path in paths)
            {
                using (var fstream = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    byte[] data = new byte[fstream.Length];
                    fstream.Read(data, 0, data.Length);

                    var name    = Path.GetFileName(path);
                    var id      = string.Format("my-file-{0}", ++count);
                    var apiFile = new ApiFileParameter(data, name, MimeMapping.GetMimeMapping(name));

                    // test pass through of custom parameters
                    apiFile.Parameters.Add("CustomValue1", string.Format("{0:N}", Guid.NewGuid()));
                    apiFile.Parameters.Add("CustomValue2", string.Format("say hello to {0}", id));

                    multipartData.Add(id, apiFile);

                    fstream.Close();
                }
            }
        }
Пример #2
0
        public Dictionary <string, object> CreateProductImageMultipartData(List <string> filePaths, int productId, string sku)
        {
            var count = 0;
            var dic   = new Dictionary <string, object>();

            // only one identifier required (product Id, Sku or Gtin).
            if (productId != 0)
            {
                dic.Add("Id", productId);
            }

            if (!string.IsNullOrEmpty(sku))
            {
                dic.Add("Sku", sku);
            }

            // also possible:
            //if (!string.IsNullOrEmpty(gtin))
            //	dic.Add("Gtin", sku);

            foreach (var path in filePaths)
            {
                using (var fstream = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    byte[] data = new byte[fstream.Length];
                    fstream.Read(data, 0, data.Length);

                    var name    = Path.GetFileName(path);
                    var id      = string.Format("my-image{0}", ++count);
                    var apiFile = new ApiFileParameter(data, name, MimeMapping.GetMimeMapping(name));

                    // test pass through of custom parameters
                    apiFile.Parameters.Add("CustomValue1", string.Format("{0:N}", Guid.NewGuid()));
                    apiFile.Parameters.Add("CustomValue2", string.Format("say hello to {0}", id));

                    dic.Add(id, apiFile);

                    fstream.Close();
                }
            }

            return(dic);
        }
		public Dictionary<string, object> CreateProductImageMultipartData(List<string> filePaths, int productId, string sku)
		{
			var count = 0;
			var dic = new Dictionary<string, object>();

			// only one identifier required (product Id, Sku or Gtin).
			if (productId != 0)
				dic.Add("Id", productId);

			if (!string.IsNullOrEmpty(sku))
				dic.Add("Sku", sku);

			// also possible:
			//if (!string.IsNullOrEmpty(gtin))
			//	dic.Add("Gtin", sku);

			foreach (var path in filePaths)
			{
				using (var fstream = new FileStream(path, FileMode.Open, FileAccess.Read))
				{
					byte[] data = new byte[fstream.Length];
					fstream.Read(data, 0, data.Length);

					var name = Path.GetFileName(path);
					var id = string.Format("my-image{0}", ++count);
					var apiFile = new ApiFileParameter(data, name, MimeMapping.GetMimeMapping(name));

					// test pass through of custom parameters
					apiFile.Parameters.Add("CustomValue1", string.Format("{0:N}", Guid.NewGuid()));
					apiFile.Parameters.Add("CustomValue2", string.Format("say hello to {0}", id));

					dic.Add(id, apiFile);

					fstream.Close();
				}
			}

			return dic;
		}