本文整理汇总了C#中UploadResult类的典型用法代码示例。如果您正苦于以下问题:C# UploadResult类的具体用法?C# UploadResult怎么用?C# UploadResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UploadResult类属于命名空间,在下文中一共展示了UploadResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadText
public override UploadResult UploadText(string text, string fileName)
{
UploadResult result = new UploadResult();
if (!string.IsNullOrEmpty(text))
{
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("secret", text);
NameValueCollection headers = null;
if (!string.IsNullOrEmpty(API_USERNAME) && !string.IsNullOrEmpty(API_KEY))
{
headers = CreateAuthenticationHeader(API_USERNAME, API_KEY);
}
result.Response = SendRequest(HttpMethod.POST, API_ENDPOINT, args, headers);
if (!string.IsNullOrEmpty(result.Response))
{
OneTimeSecretResponse jsonResponse = JsonConvert.DeserializeObject<OneTimeSecretResponse>(result.Response);
if (jsonResponse != null)
{
result.URL = URLHelpers.CombineURL("https://onetimesecret.com/secret/", jsonResponse.secret_key);
}
}
}
return result;
}
示例2: ShortenURL
public override UploadResult ShortenURL(string url)
{
UploadResult result = new UploadResult { URL = url };
if (!string.IsNullOrEmpty(url))
{
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("url", url);
result.Response = SendRequest(HttpMethod.GET, "http://turl.ca/api.php", arguments);
if (!string.IsNullOrEmpty(result.Response))
{
if (result.Response.StartsWith("SUCCESS:"))
{
result.ShortenedURL = "http://turl.ca/" + result.Response.Substring(8);
}
if (result.Response.StartsWith("ERROR:"))
{
Errors.Add(result.Response.Substring(6));
}
}
}
return result;
}
示例3: Upload
public override UploadResult Upload(Stream stream, string fileName)
{
UploadResult result = new UploadResult();
fileName = Helpers.GetValidURL(fileName);
string path = Account.GetSubFolderPath(fileName);
using (ftpClient = new FTP(Account, BufferSize))
{
ftpClient.ProgressChanged += OnProgressChanged;
try
{
IsUploading = true;
ftpClient.UploadData(stream, path);
}
finally
{
IsUploading = false;
}
}
if (!stopUpload && Errors.Count == 0)
{
result.URL = Account.GetUriPath(fileName);
}
return result;
}
示例4: Upload
public override UploadResult Upload(Stream stream, string fileName)
{
UploadResult result = new UploadResult();
string subFolderPath = Account.GetSubFolderPath();
string path = subFolderPath.CombineURL(fileName);
string url = Account.GetUriPath(fileName, subFolderPath);
OnEarlyURLCopyRequested(url);
try
{
IsUploading = true;
bool uploadResult = UploadStream(stream, path);
if (uploadResult && !StopUploadRequested && !IsError)
{
result.URL = url;
}
}
finally
{
Dispose();
IsUploading = false;
}
return result;
}
示例5: ParseResult
private UploadResult ParseResult(UploadResult result)
{
if (result.IsSuccess)
{
XDocument xd = XDocument.Parse(result.Response);
XElement xe = xd.Element("image");
if (xe != null)
{
string id = xe.GetElementValue("id");
result.URL = "http://twitsnaps.com/snap/" + id;
result.ThumbnailURL = "http://twitsnaps.com/thumb/" + id;
}
else
{
xe = xd.Element("error");
if (xe != null)
{
Errors.Add("Error: " + xe.GetElementValue("description"));
}
}
}
return result;
}
示例6: UploadSolution
public ActionResult UploadSolution(int id, HttpPostedFileBase file)
{
ActionResult redirectResult = this.RedirectToAction(
"Details",
"Courses",
new { area = "Public", id = id });
UploadResult result = new UploadResult();
if (file == null)
{
return redirectResult;
}
this.UserManagement.EnsureFolder(this.UserId);
result = this.UserManagement.SaveSolution(file, this.UserId, id);
if (!result.HasSucceed)
{
this.TempData["Error"] = result.Error;
}
else
{
this.courseService.SaveSolution(result.Path, this.UserId, id);
}
return redirectResult;
}
示例7: ShortenURL
public override UploadResult ShortenURL(string url)
{
if (customUploader.RequestType == CustomUploaderRequestType.POST && !string.IsNullOrEmpty(customUploader.FileFormName))
throw new Exception("'File form name' cannot be used with custom URL shortener.");
if (customUploader.Arguments == null || !customUploader.Arguments.Any(x => x.Value.Contains("$input$") || x.Value.Contains("%input")))
throw new Exception("Atleast one '$input$' required for argument value.");
UploadResult result = new UploadResult { URL = url };
Dictionary<string, string> args = customUploader.GetArguments(url);
result.Response = SendRequest(customUploader.GetHttpMethod(), customUploader.GetRequestURL(), args, customUploader.GetHeaders(), responseType: customUploader.ResponseType);
try
{
customUploader.ParseResponse(result, true);
}
catch (Exception e)
{
Errors.Add(Resources.CustomFileUploader_Upload_Response_parse_failed_ + Environment.NewLine + e);
}
return result;
}
示例8: UploadText
public override UploadResult UploadText(string text, string fileName)
{
UploadResult ur = new UploadResult();
if (!string.IsNullOrEmpty(text))
{
if (string.IsNullOrEmpty(APIKey))
{
APIKey = "public";
}
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("key", APIKey);
arguments.Add("description", "");
arguments.Add("paste", text);
arguments.Add("format", "simple");
arguments.Add("return", "link");
ur.Response = SendRequest(HttpMethod.POST, "http://paste.ee/api", arguments);
if (!string.IsNullOrEmpty(ur.Response) && ur.Response.StartsWith("error"))
{
Errors.Add(ur.Response);
}
else
{
ur.URL = ur.Response;
}
}
return ur;
}
示例9: ShortenURL
public override UploadResult ShortenURL(string url)
{
if (customUploader.RequestType == CustomUploaderRequestType.POST && !string.IsNullOrEmpty(customUploader.FileFormName))
throw new Exception("'File form name' cannot be used with custom URL shortener.");
if (string.IsNullOrEmpty(customUploader.RequestURL)) throw new Exception("'Request URL' must be not empty.");
if (customUploader.Arguments == null || !customUploader.Arguments.Any(x => x.Value.Contains("%input") || x.Value.Contains("$input$")))
throw new Exception("Atleast one '%input' or '$input$' required for argument value when using custom URL shortener.");
UploadResult result = new UploadResult { URL = url };
Dictionary<string, string> args = customUploader.ParseArguments(url);
if (customUploader.RequestType == CustomUploaderRequestType.POST)
{
result.Response = SendRequest(HttpMethod.POST, customUploader.RequestURL, args, customUploader.ResponseType);
}
else if (customUploader.RequestType == CustomUploaderRequestType.GET)
{
result.Response = SendRequest(HttpMethod.GET, customUploader.RequestURL, args, customUploader.ResponseType);
}
customUploader.ParseResponse(result, true);
return result;
}
示例10: ShortenURL
public override UploadResult ShortenURL(string url)
{
UploadResult result = new UploadResult { URL = url };
if (string.IsNullOrEmpty(API_HOST))
{
API_HOST = "https://polr.me/publicapi.php";
API_KEY = null;
}
else
{
API_HOST = URLHelpers.FixPrefix(API_HOST);
}
Dictionary<string, string> args = new Dictionary<string, string>();
if (!string.IsNullOrEmpty(API_KEY))
{
args.Add("apikey", API_KEY);
}
args.Add("action", "shorten");
args.Add("url", url);
string response = SendRequest(HttpMethod.GET, API_HOST, args);
if (!string.IsNullOrEmpty(response))
{
result.ShortenedURL = response;
}
return result;
}
示例11: ShortenURL
public override UploadResult ShortenURL(string url)
{
UploadResult result = new UploadResult { URL = url };
if (!string.IsNullOrEmpty(url))
{
Dictionary<string, string> arguments = new Dictionary<string, string>();
if (!string.IsNullOrEmpty(Signature))
{
arguments.Add("signature", Signature);
}
else if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password))
{
arguments.Add("username", Username);
arguments.Add("password", Password);
}
else
{
throw new Exception("Signature or Username/Password is missing.");
}
arguments.Add("action", "shorturl");
arguments.Add("url", url);
//arguments.Add("keyword", "");
//arguments.Add("title", "");
arguments.Add("format", "simple");
result.Response = SendRequest(HttpMethod.POST, APIURL, arguments);
result.ShortenedURL = result.Response;
}
return result;
}
示例12: Upload
public override UploadResult Upload(Stream stream, string fileName)
{
UploadResult result = new UploadResult();
fileName = Helpers.GetValidURL(fileName);
string subFolderPath = Account.GetSubFolderPath();
string path = subFolderPath.CombineURL(fileName);
bool uploadResult;
try
{
IsUploading = true;
uploadResult = UploadStream(stream, path);
}
finally
{
Dispose();
IsUploading = false;
}
if (uploadResult && !StopUploadRequested && !IsError)
{
result.URL = Account.GetUriPath(fileName, subFolderPath);
}
return result;
}
示例13: Upload
public override UploadResult Upload(Stream stream, string fileName)
{
if (string.IsNullOrEmpty(Host))
{
throw new Exception("ownCloud Host is empty.");
}
if (string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Password))
{
throw new Exception("ownCloud Username or Password is empty.");
}
if (string.IsNullOrEmpty(Path))
{
Path = "/";
}
string path = URLHelpers.CombineURL(Path, fileName);
string url = URLHelpers.CombineURL(Host, "remote.php/webdav", path);
url = URLHelpers.FixPrefix(url);
NameValueCollection headers = CreateAuthenticationHeader(Username, Password);
SSLBypassHelper sslBypassHelper = null;
try
{
if (IgnoreInvalidCert)
{
sslBypassHelper = new SSLBypassHelper();
}
string response = SendRequestStream(url, stream, Helpers.GetMimeType(fileName), headers, method: HttpMethod.PUT);
UploadResult result = new UploadResult(response);
if (!IsError)
{
if (CreateShare)
{
AllowReportProgress = false;
result.URL = ShareFile(path);
}
else
{
result.IsURLExpected = false;
}
}
return result;
}
finally
{
if (sslBypassHelper != null)
{
sslBypassHelper.Dispose();
}
}
}
示例14: OnLoad
protected override void OnLoad(EventArgs e)
{
UploadResult result = new UploadResult();
string typeId = (Request.Form["typeid"] ?? string.Empty).Trim();
result.CurrentTypeId = typeId;
string formPath = "music/";
int maxFileSize = SettingConfigUtility.UploadFileMaxSize * 1000;
if (Request.Files.Count > 0)
{
HttpPostedFile file = Request.Files[0];
if (file == null)
{
result.IsSuccess = false;
result.Message = "没有检测到<br>系统上传的音频文件";
this.RenderUploadResult(result);
}
else
{
string fileName = file.FileName;
fileName = Path.GetFileName(fileName);
int fileSize = file.ContentLength;
if (fileSize > 0)
{
if (fileSize > maxFileSize)
{
result.IsSuccess = false;
result.FileName = fileName;
result.Message = string.Format("因音频大于{0}KB", SettingConfigUtility.UploadFileMaxSize);
this.RenderUploadResult(result);
}
try
{
file.SaveAs(Server.MapPath(formPath + fileName));
}
catch (Exception)
{
result.IsSuccess = false;
result.FileName = fileName;
result.Message = "因上传出现未知错误";
this.RenderUploadResult(result);
}
result.IsSuccess = true;
result.FileName = fileName;
this.RenderUploadResult(result);
}
else
{
result.IsSuccess = false;
result.FileName = fileName;
result.Message = "因音频太小";
this.RenderUploadResult(result);
}
}
}
base.OnLoad(e);
}
示例15: ProcessRequest
public void ProcessRequest(HttpContext context) {
context.Response.ContentType = "text/plain";
var uploads = new List<UploadFileInfo>();
var basePath = HttpContext.Current.Request.Form["path"];
if (!basePath.StartsWith(SiteSettings.Instance.FilePath)) {
var exception = new AccessViolationException(string.Format("Wrong path for uploads! {0}", basePath));
Logger.Write(exception, Logger.Severity.Major);
throw exception;
}
basePath = HttpContext.Current.Server.MapPath(basePath);
foreach (string file in context.Request.Files) {
var postedFile = context.Request.Files[file];
string fileName;
if (postedFile.ContentLength == 0) {
continue;
}
if (postedFile.FileName.Contains("\\")) {
string[] parts = postedFile.FileName.Split(new[] {'\\'});
fileName = parts[parts.Length - 1];
}
else {
fileName = postedFile.FileName;
}
if (IsFileExtensionBlocked(fileName)) {
Logger.Write(string.Format("Upload of {0} blocked since file type is not allowed.", fileName), Logger.Severity.Major);
uploads.Add(new UploadFileInfo {
name = Path.GetFileName(fileName),
size = postedFile.ContentLength,
type = postedFile.ContentType,
error = "Filetype not allowed!"
});
continue;
}
var savedFileName = GetUniqueFileName(basePath, fileName);
postedFile.SaveAs(savedFileName);
uploads.Add(new UploadFileInfo {
name = Path.GetFileName(savedFileName),
size = postedFile.ContentLength,
type = postedFile.ContentType
});
}
var uploadResult = new UploadResult(uploads);
var serializedUploadInfo = Serialization.JsonSerialization.SerializeJson(uploadResult);
context.Response.Write(serializedUploadInfo);
}