Upload test complete

Fix Uploader class missing arg
This commit is contained in:
Matthew Burnett 2018-04-19 23:03:28 -04:00
parent bfdede32eb
commit d5bc81fc46
2 changed files with 33 additions and 7 deletions

View file

@ -159,7 +159,7 @@ public virtual void StopUpload()
protected NameValueCollection SendRequestGetHeaders(HttpMethod method, string url, Stream data, string contentType, Dictionary<string, string> args,
NameValueCollection headers = null, CookieCollection cookies = null)
{
using (HttpWebResponse response = GetResponse(method, url, data, contentType, null, headers, cookies))
using (HttpWebResponse response = GetResponse(method, url, data, contentType, args, headers, cookies))
{
if (response != null)
{

View file

@ -1,5 +1,9 @@
using System.Collections.Generic;
using ShareX.HelpersLib;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace ShareX.UploadersLib.FileUploaders
{
@ -16,25 +20,47 @@ public override GenericUploader CreateUploader(UploadersConfig config, TaskRefer
{
return new GoogleCloudStorage
{
APIKey = "null"
token = "",
bucket = "cdn.riolu.com"
};
}
}
public sealed class GoogleCloudStorage : FileUploader
{
public string APIKey { get; set; }
public string token { get; set; }
public string bucket { get; set; }
public override UploadResult Upload(Stream stream, string fileName)
{
string uploadurl = $"https://www.googleapis.com/upload/storage/v1/b/{bucket}/o";
string objecturl = $"https://www.googleapis.com/upload/storage/v1/b/{bucket}/o/{fileName}/acl";
string publicurl = $"https://storage.googleapis.com/{bucket}/{fileName}";
string contentType = Helpers.GetMimeType(fileName);
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("key", APIKey);
args.Add("uploadType", "media");
args.Add("name", fileName);
return null;
NameValueCollection headers = new NameValueCollection
{
["Content-Length"] = stream.Length.ToString(),
["Authorization"] = "Bearer " + token
};
NameValueCollection responseHeaders = SendRequestGetHeaders(HttpMethod.POST, uploadurl, stream, contentType, args, headers);
if (responseHeaders == null)
{
Errors.Add("Upload to Google Cloud Storage failed.");
return null;
}
return new UploadResult
{
IsSuccess = true,
URL = publicurl
};
}
}
}