mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 05:53:27 -07:00
Untested performance improvements with uploads, in short the image is directly stored to the upload stream instead of writing a stream to a byte[]. Expecting a small performance improvement, and a lot less memory usage while uploading.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2125 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
c983567827
commit
abe79e65e9
6 changed files with 230 additions and 182 deletions
|
@ -110,37 +110,34 @@ namespace GreenshotPhotobucketPlugin {
|
|||
/// <returns>true if the upload succeeded</returns>
|
||||
public bool Upload(ICaptureDetails captureDetails, Image image, out string uploadURL) {
|
||||
OutputSettings outputSettings = new OutputSettings(config.UploadFormat, config.UploadJpegQuality, config.UploadReduceColors);
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
ImageOutput.SaveToStream(image, stream, outputSettings);
|
||||
try {
|
||||
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
|
||||
PhotobucketInfo photobucketInfo = null;
|
||||
try {
|
||||
string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
|
||||
PhotobucketInfo photobucketInfo = null;
|
||||
|
||||
// Run upload in the background
|
||||
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("photobucket", LangKey.communication_wait),
|
||||
delegate() {
|
||||
photobucketInfo = PhotobucketUtils.UploadToPhotobucket(stream.GetBuffer(), (int)stream.Length, captureDetails.Title, filename);
|
||||
}
|
||||
);
|
||||
// This causes an exeption if the upload failed :)
|
||||
LOG.DebugFormat("Uploaded to Photobucket page: " + photobucketInfo.Page);
|
||||
uploadURL = null;
|
||||
try {
|
||||
if (config.UsePageLink) {
|
||||
uploadURL = photobucketInfo.Page;
|
||||
Clipboard.SetText(photobucketInfo.Page);
|
||||
} else {
|
||||
uploadURL = photobucketInfo.Original;
|
||||
Clipboard.SetText(photobucketInfo.Original);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("Can't write to clipboard: ", ex);
|
||||
// Run upload in the background
|
||||
new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("photobucket", LangKey.communication_wait),
|
||||
delegate() {
|
||||
photobucketInfo = PhotobucketUtils.UploadToPhotobucket(image, outputSettings, captureDetails.Title, filename);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOG.Error(e);
|
||||
MessageBox.Show(Language.GetString("photobucket", LangKey.upload_failure) + " " + e.Message);
|
||||
);
|
||||
// This causes an exeption if the upload failed :)
|
||||
LOG.DebugFormat("Uploaded to Photobucket page: " + photobucketInfo.Page);
|
||||
uploadURL = null;
|
||||
try {
|
||||
if (config.UsePageLink) {
|
||||
uploadURL = photobucketInfo.Page;
|
||||
Clipboard.SetText(photobucketInfo.Page);
|
||||
} else {
|
||||
uploadURL = photobucketInfo.Original;
|
||||
Clipboard.SetText(photobucketInfo.Original);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("Can't write to clipboard: ", ex);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LOG.Error(e);
|
||||
MessageBox.Show(Language.GetString("photobucket", LangKey.upload_failure) + " " + e.Message);
|
||||
}
|
||||
uploadURL = null;
|
||||
return false;
|
||||
|
|
|
@ -29,6 +29,7 @@ using System.Web;
|
|||
|
||||
using GreenshotPlugin.Core;
|
||||
using Greenshot.IniFile;
|
||||
using Greenshot.Plugin;
|
||||
|
||||
namespace GreenshotPhotobucketPlugin {
|
||||
/// <summary>
|
||||
|
@ -47,7 +48,7 @@ namespace GreenshotPhotobucketPlugin {
|
|||
/// </summary>
|
||||
/// <param name="imageData">byte[] with image data</param>
|
||||
/// <returns>PhotobucketResponse</returns>
|
||||
public static PhotobucketInfo UploadToPhotobucket(byte[] imageData, int dataLength, string title, string filename) {
|
||||
public static PhotobucketInfo UploadToPhotobucket(Image image, OutputSettings outputSettings, string title, string filename) {
|
||||
string responseString;
|
||||
|
||||
OAuthSession oAuth = new OAuthSession("149833145", "ebd828180b11103c010c7e71c66f6bcb");
|
||||
|
@ -77,7 +78,7 @@ namespace GreenshotPhotobucketPlugin {
|
|||
oAuth.Token = config.Token;
|
||||
oAuth.TokenSecret = config.TokenSecret;
|
||||
|
||||
Dictionary<string ,string> parameters = new Dictionary<string, string>();
|
||||
Dictionary<string, object> parameters = new Dictionary<string, object>();
|
||||
// add album
|
||||
parameters.Add("id", "Apex75/greenshot");
|
||||
// add type
|
||||
|
@ -95,7 +96,7 @@ namespace GreenshotPhotobucketPlugin {
|
|||
oAuth.Sign(HTTPMethod.POST, apiUrl, parameters);
|
||||
apiUrl = apiUrl.Replace("api.photobucket.com", config.SubDomain);
|
||||
// Add image
|
||||
parameters.Add("uploadfile", new FileParameter(imageData, filename, "image/png", dataLength));
|
||||
parameters.Add("uploadfile", new ImageParameter(image, outputSettings, filename));
|
||||
responseString = oAuth.MakeRequest(HTTPMethod.POST, apiUrl, parameters, null, null);
|
||||
} catch (Exception ex) {
|
||||
LOG.Error("Error uploading to Photobucket.", ex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue