mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
Upload test complete
Fix Uploader class missing arg
This commit is contained in:
parent
bfdede32eb
commit
d5bc81fc46
2 changed files with 33 additions and 7 deletions
|
@ -159,7 +159,7 @@ public string SendRequestURLEncoded(HttpMethod method, string url, Dictionary<st
|
|||
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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue