private async Task UploadImageToImgur() { try { _isUploaded = false; uploadingLabel.Visible = true; // Create connection to API var apiClient = new ApiClient("21d68b39c14c68e"); var httpClient = new HttpClient(); // Select image for upload var filePath = photoBrowser.FileName; using var fileStream = File.OpenRead(filePath); // Create end point and upload image var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream); _movie.Picture = imageUpload.Link; _isUploaded = true; uploadingLabel.Visible = false; if (_isNew) { return; } // Save the image url to the database await SettingController.UpdateImageLink(_movie.Picture, "movie", _movie.Id); } catch { uploadingLabel.Visible = false; CustomMessageBox.Show(@"Something went wrong, please try again."); } }
public async Task <string> UploadImg2(ImguploadDto dto) { if (dto != null) { //convert base64 to byte[] byte[] imageBytes = Convert.FromBase64String(dto.base64String); //convert byte[] to imgStream // var imgStream = System.Text.Encoding.UTF8.GetString(imageBytes); var imgStream = new MemoryStream(imageBytes); //Imgurapi var apiClient = new ApiClient("0a9f2fb7434821b", "60f9a494f1607de3b90582298fc88c8e29560199"); var httpClient = new HttpClient(); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(imgStream); return(imageUpload.Link); } else { return("dataURL= null"); } }
public async Task <IActionResult> Get(string url = "https://silverdimond.tk") { var imageEndpoint = new ImageEndpoint(ApiClient, HttpClient); var imageUpload = await imageEndpoint.UploadImageAsync(new MemoryStream(await Browser.RenderUrlAsyncAsByteArray(url))); return(Redirect(imageUpload.Link)); }
private async Task UploadImageToImgur() { try { uploadingLabel.Visible = true; // Create connection to API var apiClient = new ApiClient("21d68b39c14c68e"); var httpClient = new HttpClient(); // Select image for upload var filePath = photoBrowser.FileName; using var fileStream = File.OpenRead(filePath); // Create end point and upload image var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream); // Save the image url to the database await SettingController.UpdateImageLink(imageUpload.Link, "account", Account.GetAccountInstance().Id); uploadingLabel.Visible = false; } catch { CustomMessageBox.Show(@"Something went wrong, please try again."); } }
public async Task UploadImageProgressStream_UploadsImage() { var totalProgress = 0; var apiClient = _fixture.GetApiClientWithKey(); var httpClient = new HttpClient(); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "banana.jpg"); using var fileStream = File.OpenRead(filePath); void report(int progress) { totalProgress += progress; } var uploadProgress = new Progress <int>(report); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream, progress : uploadProgress, bufferSize : 4096); var imageDeleted = await imageEndpoint.DeleteImageAsync(imageUpload.DeleteHash); Assert.NotNull(imageUpload); Assert.True(imageDeleted); _output.WriteLine($"{totalProgress} of {fileStream.Length} reported."); }
public async Task <IHttpActionResult> Upload() { var httpRequest = HttpContext.Current.Request; // var postedFile = httpRequest.Files[file]; if (httpRequest != null) { // ImgstringList = new List<string>(); // var files = Request.files; var File = HttpContext.Current.Request.Files[0]; //Imgurapi var apiClient = new ApiClient("0a9f2fb7434821b", "60f9a494f1607de3b90582298fc88c8e29560199"); var httpClient = new HttpClient(); // var fileName = File.FileName;/*C:\Users\User\source\repos\mikeyeh40709\Xboox\Xboox\Assets\Image\Pics\*/ // session["fileName"]=1 //從這裡開始可以用imgur // var path = Path.Combine(Server.MapPath("../Assets/Pics"), fileName); // files[0].SaveAs(path); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(File.InputStream); ProductService.GetImg().Add(imageUpload.Link); } //; //return Json($"fileUpload {Session["fileName"]}"); return(Json(ProductService.GetImg())); }
private async Task UploadImage(ImageViewModel imageViewModel, ImageEndpoint imageEndpoint) { IImage imageData = await imageEndpoint.UploadImageAsync(imageViewModel.Image.OpenReadStream()); imageViewModel.ImagePath = imageData.Link; imageViewModel.ImageId = imageData.Id; }
public async Task Upload([Optional] string url) { if (string.IsNullOrWhiteSpace(url)) { url = Context.Message.Attachments.FirstOrDefault().Url; } else if (string.IsNullOrWhiteSpace(url) && Context.Message.Attachments.FirstOrDefault() == null) { await ReplyAsync($"Don't be a Howard! You need to link an image or attach an image!"); } var apiclient = new ApiClient("853f0d7b758b42b", "9c1c12e7e7f370e81e8f49d83b283b52ca04b006"); var httpclient = new HttpClient(); string filename = ""; if (url.EndsWith("f")) { filename = "1.gif"; } else { filename = "1.png"; } webClient.DownloadFile(url, filename); var filepath = $@"{filename}"; using var fileStream = File.OpenRead(filepath); var imageEndpoint = new ImageEndpoint(apiclient, httpclient); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream); await Utilities.SendEmbed(Context.Channel, "Imgur Upload", $"Your image can be found here {imageUpload.Link}", Discord.Color.Blue, "", imageUpload.Link); File.Delete($@"{filename}"); }
public async Task <string> UpLoadImg(HttpPostedFile file) { //HttpFileCollection files = HttpContext.Current.Request.Files; //HttpPostedFile file = files[0]; if (file == null || file.ContentLength == 0) { return(null); } try { BinaryReader binaryReader = new BinaryReader(file.InputStream); byte[] byteArray = binaryReader.ReadBytes(file.ContentLength); var apiClient = new ApiClient("7cc84057ff7498d"); var httpClient = new HttpClient(); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(new MemoryStream(byteArray)); return("成功" + imageUpload.Link); } catch (Exception ex) { return("失敗" + ex.ToString()); } }
public static void PostToImgur(ref PostRequest model) { var client = new ApiClient(Constants.Config.imgur.apikey); var endpoint = new ImageEndpoint(client, Program.HttpClient); C.Write("Uploading to Imgur..."); //Imgur can only handle Images of 10MB. var tenMb = 10400000; try { IImage image; if (model.RequestSize > tenMb) { //Download the image C.Write("Resizing image..."); using (var imageFromUrl = GetImageFromUrl(model.RequestUrl)) { using (var imageResized = GetSpecificSize(imageFromUrl, tenMb, true)) { Stream result = imageResized != null? EncodeProperly(imageResized, ImageFormat.Png) : EncodeProperly(imageFromUrl, ImageFormat.Jpeg); image = endpoint.UploadImageAsync(result, null, model.Title, model.Description) .Result; } } } else { image = endpoint.UploadImageAsync(model.RequestUrl, null, model.Title, model.Description).Result; } model.ResultUrl = image.Link; model.DeleteHash = image.DeleteHash; } catch (Exception) { //Fallback! model.ResultUrl = model.RequestUrl; } C.WriteLineNoTime("Done!"); }
public async Task <string> UploadImageAsync(Stream stream) { var apiClient = new ApiClient(setting.ClientId); var httpClient = new HttpClient(); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(stream); return(imageUpload.Link); }
public static void PostToImgurAsGif(ref PostRequest model) { C.Write("Uploading to Imgur..."); var client = new ApiClient(Constants.Config.imgur.apikey); ImageEndpoint endpoint = new ImageEndpoint(client, Program.HttpClient); var image = endpoint.UploadImageAsync(model.RequestUrl, null, model.Title, model.Description).Result; model.ResultUrl = image.Link; model.DeleteHash = image.DeleteHash; C.WriteLineNoTime("Done!"); }
//public ImgurService() //{ // Console.WriteLine("start"); // var apiClient = new ApiClient("541a79f12e7772b"); // var httpClient = new HttpClient(); // var oAuth2Endpoint = new OAuth2Endpoint(apiClient, httpClient); // var authUrl = oAuth2Endpoint.GetAuthorizationUrl(); // var token = new OAuth2Token // { // AccessToken = "4eef8487399dffa10a3d7b20058ebd95b6648784", // RefreshToken = "f8de7ef58c55a44b450933028811f5efe477a45a", // AccountId = 138100559, // AccountUsername = "******", // ExpiresIn = 315360000, // TokenType = "bearer" // }; // apiClient.SetOAuth2Token(token); // var imageEndpoint = new ImageEndpoint(apiClient, httpClient); //} public string UploadImgur(HttpPostedFileBase file) { var apiClient = new ApiClient("541a79f12e7772b", "c824e682983f55dc1e2642b38741d657d4206db3"); var httpClient = new HttpClient(); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = imageEndpoint.UploadImageAsync(file.InputStream); var ImgPath = imageUpload.Result.Link; return(ImgPath); }
public async Task <(string, string)> UploadPhoto(Stream stream, string name) { using (var httpClient = new HttpClient()) { var apiClient = new ApiClient("dc7aa47e53edfa9"); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(stream, null, null, name); return(imageUpload.Link, imageUpload.Title); } }
public async Task <string> UploadImageAsync(MemoryStream fileStream) { var apiClient = new ApiClient(_options.ClientId); var httpClient = new HttpClient(); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); fileStream.Seek(0, SeekOrigin.Begin); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream); await fileStream.DisposeAsync(); return(imageUpload.Link); }
public async Task UploadImageUrl_UploadsImage() { var apiClient = _fixture.GetApiClientWithKey(); var httpClient = new HttpClient(); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "banana.jpg"); using var fileStream = File.OpenRead(filePath); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream); var imageUrlUpload = await imageEndpoint.UploadImageAsync(imageUpload.Link); var imageDeleted = await imageEndpoint.DeleteImageAsync(imageUpload.DeleteHash); var imageUrlDeleted = await imageEndpoint.DeleteImageAsync(imageUrlUpload.DeleteHash); Assert.NotNull(imageUrlUpload); Assert.NotEqual(imageUpload.Id, imageUrlUpload.Id); Assert.True(imageDeleted); Assert.True(imageUrlDeleted); }
public async Task <string> UploadImage(Stream stream) { try { IImage image = await _endpoint.UploadImageAsync(stream); return(image.Link); } catch (ImgurException Exception) { Logger.Log(LogType.Imgur, ConsoleColor.Red, "Upload", "An error occured while uploading an image:" + Environment.NewLine + Exception.Message); } return(""); }
public async Task UploadImageAsync_WithImageNull_ThrowsArgumentNullException() { var apiClient = new ApiClient("123"); var endpoint = new ImageEndpoint(apiClient, new HttpClient()); var exception = await Record.ExceptionAsync(async() => { await endpoint.UploadImageAsync(image: null); }); Assert.NotNull(exception); Assert.IsType <ArgumentNullException>(exception); var argNullException = (ArgumentNullException)exception; Assert.Equal("image", argNullException.ParamName); }
public async Task UploadImageUrlAsync_Equal() { var mockUrl = "https://api.imgur.com/3/image"; var mockResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(MockImageResponses.UploadImage) }; var apiClient = new ApiClient("123"); var httpClient = new HttpClient(new MockHttpMessageHandler(mockUrl, mockResponse)); var endpoint = new ImageEndpoint(apiClient, httpClient); var response = await endpoint.UploadImageAsync(mockUrl); Assert.NotNull(response); Assert.IsAssignableFrom <IImage>(response); Assert.Equal("mvWNMH4", response.Id); }
public async Task UploadVideoStream_UploadsVideo() { var apiClient = _fixture.GetApiClientWithKeyAndOAuthToken(); var httpClient = new HttpClient(); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "banana.mp4"); using var fileStream = File.OpenRead(filePath); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream); var imageDeleted = await imageEndpoint.DeleteImageAsync(imageUpload.Id); Assert.NotNull(imageUpload); Assert.True(imageDeleted); }
public async Task <string> UploadToImgur(string _filename) { var apiClient = new ApiClient(clientId); var httpClient = new HttpClient(); Console.WriteLine("Loading screenshot..."); using var fileStream = File.OpenRead(_filename); Console.WriteLine("Loaded screenshot"); Console.WriteLine("Uploading to Imgur..."); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream); var imageLink = imageUpload.Link; Console.WriteLine($"Uploaded to Imgur: {imageLink}"); return(imageUpload.Link); }
public async Task <string> Resolve(string deckFilePath, CancellationToken cancellationToken) { var imageFilePath = RelatedImageResolver.Find(deckFilePath); if (imageFilePath == null) { return(null); } using var fileStream = File.OpenRead(imageFilePath); var imageUpload = await _imageEndpoint.UploadImageAsync(fileStream); var link = imageUpload.Link; var urlFilePath = Path.ChangeExtension(deckFilePath, ".url"); // Cache imgur location for next invocation await File.WriteAllTextAsync(urlFilePath, link); return(link); }
public async Task UpdateImage_UpdatesImage() { var apiClient = _fixture.GetApiClientWithKey(); var httpClient = new HttpClient(); var filePath = Path.Combine(Directory.GetCurrentDirectory(), "banana.jpg"); using var fileStream = File.OpenRead(filePath); var imageEndpoint = new ImageEndpoint(apiClient, httpClient); var imageUpload = await imageEndpoint.UploadImageAsync(fileStream, title : "uploaded"); await imageEndpoint.UpdateImageAsync(imageUpload.DeleteHash, title : "updated"); var image = await imageEndpoint.GetImageAsync(imageUpload.Id); var imageDeleted = await imageEndpoint.DeleteImageAsync(imageUpload.DeleteHash); Assert.NotNull(imageUpload); Assert.Equal("uploaded", imageUpload.Title); Assert.Equal("updated", image.Title); Assert.True(imageDeleted); }
public string MemberSetup(CMemberEditor m) { var data = ""; CMember member = Session[CMemberSession.Session_Login_User] as CMember; if (m.fPhoto == null && m.NewfPassword == null) { List <CMember> SELECTMember = CMemberFactory.fn會員查詢(); CMember cMember = SELECTMember.FirstOrDefault(n => n.fMemberId == member.fMemberId); if (cMember != null) { if (m.MemberImage != null) { string photoName = Guid.NewGuid().ToString(); photoName += Path.GetExtension(m.MemberImage.FileName); var A = Server.MapPath(@"~/Image/MemberImage/" + photoName); m.MemberImage.SaveAs(Server.MapPath("../Image/MemberImage/" + photoName)); var CLIENT_ID = "b6ff140d7b00eef"; var CLIENT_SECRET = "5008867fee0b01b1a3e9ccbc0d82ccee76290f7d"; //建立ImgurClient(其中的"CLIENT_ID", "CLIENT_SECRET"要換成你自己的) var client = new ApiClient(CLIENT_ID, CLIENT_SECRET); var httpClient = new HttpClient(); var endpoint = new ImageEndpoint(client, httpClient); var ImgPath = Server.MapPath(@"~/Image/MemberImage/" + photoName); IImage image; //取得圖片檔案FileStream using (var fs = new FileStream(ImgPath, FileMode.Open)) { image = endpoint.UploadImageAsync(fs).GetAwaiter().GetResult(); } cMember.fPhoto = image.Link; System.IO.File.Delete(ImgPath); //顯示圖檔位置 Response.Write("Image uploaded. Image Url: " + image.Link); m.MemberImage.SaveAs(A); cMember.fAccount = m.fAccount; cMember.fPassword = m.fPassword; cMember.fFirstName = m.fFirstName; cMember.fLastName = m.fLastName; cMember.fTheNickName = m.fTheNickName; cMember.fGender = m.fGender; cMember.fBirthDay = m.fBirthDay; cMember.fTheAddress = m.fTheAddress; cMember.fMobilePhone = m.fMobilePhone; CMemberFactory.fn會員更新(cMember); Session[CMemberSession.Session_Login_User] = cMember; data = "修改成功"; return(data); } else { cMember.fAccount = m.fAccount; cMember.fPassword = m.fPassword; cMember.fFirstName = m.fFirstName; cMember.fLastName = m.fLastName; cMember.fTheNickName = m.fTheNickName; cMember.fGender = m.fGender; cMember.fBirthDay = m.fBirthDay; cMember.fTheAddress = m.fTheAddress; cMember.fMobilePhone = m.fMobilePhone; CMemberFactory.fn會員更新(cMember); Session[CMemberSession.Session_Login_User] = cMember; data = "修改成功"; return(data); } } else { data = "修改失敗"; return(data); } } data = "修改失敗"; return(data); }