Esempio n. 1
0
        public static FileStream CopyImageGetStream(byte[] data)
        {
            string rdFileName = Guid.NewGuid().ToString().Substring(0, 6) + OptionText_Helper.ReadAllText("Account") + ".jpeg";

            string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), rdFileName);

            File.WriteAllBytes(filePath, data);

            FileStream inStream = new FileStream(filePath, FileMode.Open);

            return(inStream);
        }
        public static async Task <string> PostUpLoadImageHelperAsync(string url, Stream stream)
        {
            //上传图片到服务器
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(HttpBaseAddress);
            client.DefaultRequestHeaders.Accept.Clear();
            #region
            MultipartFormDataContent form        = new MultipartFormDataContent();
            StreamContent            fileContent = new StreamContent(stream);
            fileContent.Headers.ContentType                 = new MediaTypeHeaderValue("application/octet-stream");
            fileContent.Headers.ContentDisposition          = new ContentDispositionHeaderValue("form-data");
            fileContent.Headers.ContentDisposition.FileName = OptionText_Helper.ReadAllText("Account") + ".jpeg";
            form.Add(fileContent);
            #endregion

            try
            {
                HttpResponseMessage response = await client.PostAsync(url, form);

                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsAsync <string>());
                }
                else
                {
                    return("no");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                client.Dispose();
            }
        }