本文整理汇总了C#中RestSharp.RestRequest.AddFile方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddFile方法的具体用法?C# RestRequest.AddFile怎么用?C# RestRequest.AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestRequest
的用法示例。
在下文中一共展示了RestRequest.AddFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: upload
public static void upload(String content, String filename, byte[] file, Action<RestResponse> callback)
{
RestClient client = WbtoApi.GetClient();
RestRequest request = new RestRequest("/api/upload.json", Method.POST);
request.AddParameter("source", Constants.SOURCE);
request.AddParameter("content", content);
request.AddFile("file", file, filename);
client.ExecuteAsync(request, callback);
}
示例2: UploadFile
public void UploadFile(string path, string projectName, MediaItem mediaItem)
{
var fullPath = path + mediaItem.Filename;
var request = new RestRequest("UploadMediaItem");
request.AddParameter("path", mediaItem.Filename);
request.AddParameter("project", projectName);
request.AddFile(mediaItem.Filename, fullPath);
var res=Client.Post(request);
}
示例3: AddLog
/// <summary>
/// Add log to server
/// </summary>
/// <param name="param"></param>
public void AddLog(LogParameter param)
{
var request = new RestRequest("/api/v1/add_log", Method.POST)
{
AlwaysMultipartFormData = true
};
request.AddHeader("Content-Type", "multipart/form-data");
if (param.Type.HasValue)
request.AddParameter("type", LogTypeExt.DisplayName(param.Type.Value)); // adds to POST or URL querystring based on Method
if (param.UserId != null)
request.AddParameter("user_id", param.UserId);
if (param.FilePath != null)
request.AddFile("image_file", param.FilePath);
client.Execute(request);
}
示例4: DeliverEvergreenMessage
public static bool DeliverEvergreenMessage(string emailMessage, string to, string attachment)
{
try
{
//Deliver email to Evergreen
var client = new RestClient();
client.BaseUrl = "https://api.mailgun.net/v2";
client.Authenticator = new HttpBasicAuthenticator("api", Supplier.MailgunApiKey);
RestRequest request = new RestRequest();
request.AddParameter("domain", Supplier.MailgunDomain, ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
request.AddParameter("from", Supplier.CompanyName + " <[email protected]>");
request.AddParameter("to", to);
request.AddParameter("subject", "New Order Notification");
request.AddParameter("html", emailMessage);
request.AddFile("attachment", attachment);
request.Method = Method.POST;
var response = client.Execute(request);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return true;
}
}
catch (Exception ex)
{
Log.WriteErrorLog(ex);
}
return false;
}
示例5: CallApiAsync
public async Task<Object> CallApiAsync(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams, String[] AuthSettings) {
var request = new RestRequest(Path, Method);
UpdateParamsForAuth(QueryParams, HeaderParams, AuthSettings);
// add default header, if any
foreach(KeyValuePair<string, string> defaultHeader in this.defaultHeaderMap)
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
// add header parameter, if any
foreach(KeyValuePair<string, string> param in HeaderParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(KeyValuePair<string, string> param in QueryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(KeyValuePair<string, string> param in FormParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(KeyValuePair<string, string> param in FileParams)
request.AddFile(param.Key, param.Value);
if (PostBody != null) {
request.AddParameter("application/json", PostBody, ParameterType.RequestBody); // http body (model) parameter
}
return (Object) await restClient.ExecuteTaskAsync(request);
}
示例6: Create
/*
* This method is used to create or POST the document for a given user in the SignNow Application
*/
public Document Create(Oauth2Token token, Document documentPath)
{
Document document = null;
try
{
string requestBody = JsonConvert.SerializeObject(documentPath.FilePath, Formatting.Indented);
var client = new RestClient();
client.BaseUrl = config.GetApiBase();
var request = new RestRequest("/document", Method.POST)
.AddHeader("Accept", "application/json")
.AddHeader("Authorization", "Bearer " + token.AccessToken)
.AddHeader("Content-Type","multipart/form-data");
request.AddFile("file", documentPath.FilePath);
var httpResponse = client.Execute(request);
string json = httpResponse.Content.ToString();
document = JsonConvert.DeserializeObject<Document>(json);
}
catch(Exception ex)
{
Console.WriteLine(string.Format("Exception: {0}", ex.Message));
throw;
}
return document;
}
示例7: ExecuteJobRequest
private string ExecuteJobRequest(RestClient client)
{
var req = new RestRequest(@"1/job", Method.POST);
req.AlwaysMultipartFormData = true;
req.AddParameter("apikey", ApiKey);
req.AddParameter("job", JsonConvert.SerializeObject(_batch));
foreach (var v in _files)
{
req.AddFile(v.Key, v.Value);
}
string resp = null;
client.ExecuteAsync(req, response => { resp = response.Content; });
DateTime timeoutTime = DateTime.Now + TimeoutSpan;
while (string.IsNullOrEmpty(resp) && DateTime.Now < timeoutTime)
{
System.Threading.Thread.Sleep(1000);
}
if (resp == null)
{
throw new TimeoutException("Initial job request timed out");
}
return resp;
}
示例8: GetUploadRequest
public static RestRequest GetUploadRequest(string filename)
{
var request = new RestRequest("/path/data/", Method.POST);
request.AddFile("file", filename);
return request;
}
示例9: PrepareRequest
// Creates and sets up a RestRequest prior to a call.
private RestRequest PrepareRequest(
String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams)
{
var request = new RestRequest(path, method);
// add path parameter, if any
foreach(var param in pathParams)
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
// add header parameter, if any
foreach(var param in headerParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(var param in queryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(var param in formParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(var param in fileParams)
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
if (postBody != null) // http body (model) parameter
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
return request;
}
示例10: UploadScreenshot
public PonyShotsResponse UploadScreenshot(string shotPath)
{
RestClient restClient = new RestClient(UploadUrl);
RestRequest restRequest = new RestRequest(Method.POST);
restRequest.AddParameter("username", Username);
restRequest.AddParameter("apikey", ApiKey);
restRequest.AddFile("image", shotPath, "image/png");
var resp = restClient.Execute(restRequest);
JPSResponse jValue = JsonConvert.DeserializeObject<JPSResponse>(resp.Content);
PonyShotsResponse psResp = new PonyShotsResponse();
psResp.RawResponse = resp.Content;
psResp.Error = jValue.error;
if (!psResp.Error)
{
psResp.Slug = jValue.slug;
}
else
{
psResp.ErrorMessage = jValue.message;
}
return psResp;
}
示例11: PostLogFile
private void PostLogFile(string macAddress, Guid requestId, Guid logFileId, string fileName)
{
string path = GetFilePath(fileName);
if (!File.Exists(path))
{
Logger.Instance.Write("PostLogFile", LogLevel.Medium, "PostLog failed as the log file does not exist.");
RequestComponent.GetInstance().FinishRequest(macAddress, RequestInputModel.From(requestId, false));
return;
}
var request = new RestRequest("v1/signboards/{macAddress}/logFiles/{logFileId}/file", Method.POST);
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddUrlSegment("macAddress", macAddress);
request.AddUrlSegment("logFileId", logFileId.ToString());
request.AddBody(DeviceLogModel.From(fileName));
request.AddFile("file", File.ReadAllBytes(path), Path.GetFileName(path), "multipart/form-data");
Client.ExecuteAsync<DeviceLogResponseModel>(request, (response) =>
{
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
Logger.Instance.Write("PostLogFile", LogLevel.Low, "Uploaded log file successfully.");
RequestComponent.GetInstance().FinishRequest(macAddress, RequestInputModel.From(requestId, true));
return;
}
else
{
Logger.Instance.Write("PostLog", LogLevel.Medium, "PostLog request failed. ");
RequestComponent.GetInstance().FinishRequest(macAddress, RequestInputModel.From(requestId, false));
return;
}
});
}
示例12: Upload
public KrakenResponse Upload(KrakenRequest kr, string fileName, string fileExtension)
{
var request = new RestRequest("upload", Method.POST);
if (kr.File.Length == 0)
{
return new KrakenResponse()
{
Success = false,
Error = "File parameter was not provided"
};
}
kr.Auth = _auth;
request.AddFile("image_bytes", kr.File, fileName + fileExtension);
kr.File = null;
string json = JsonConvert.SerializeObject(kr, serializerSettings);
request.AddParameter("json", json);
var result = Request(request);
return result;
}
示例13: UploadFile
/// <summary>
/// Uploads a file, if the request fails this overload will delete the note record
/// </summary>
/// <param name="module">Notes</param>
/// <param name="id">Record ID</param>
/// <param name="filePath">Path to file on local disk</param>
/// <param name="deleteOnFailure">Bool: deletes record if upload fails</param>
/// <returns>Bool</returns>
public bool UploadFile(string module, string id, string filePath, bool deleteOnFailure)
{
var request = new RestRequest("{module}/{id}/file/filename", Method.POST);
request.AddUrlSegment("module", module);
request.AddUrlSegment("id", id);
request.AddParameter("format", "sugar-html-json");
request.AddParameter("delete_if_fails", deleteOnFailure);
if (deleteOnFailure)
{
request.AddParameter("oauth_token", Token);
}
if (!File.Exists(filePath))
{
//@todo create a SugarFileException class
throw new SugarException("Can not locate file path. Path attempted = " + filePath);
}
request.AddFile("filename", filePath);//?
FileUploadResponse response = Execute<FileUploadResponse>(request);
return ! string.IsNullOrEmpty(response.filename.name);
}
示例14: RESTUploadUserLook
public IRestResponse<_REST_StylesetHashInfo> RESTUploadUserLook(long lookId, long matchUserLookId, string filePath1, string filePath2, string filePath3, string MembershipId)
{
var Client = new RestClient();
Client.BaseUrl = baseUri;
MembershipId = "2011003539244269";
var Request = new RestRequest("/api/userLook", Method.POST);
Request.AddParameter("membershipId", MembershipId);
Request.AddParameter("lookId", lookId);
Request.AddParameter("matchUserLookId", matchUserLookId);
Request.AddFile("front", filePath1);
Request.AddFile("noface", filePath2);
Request.AddFile("back", filePath3);
IRestResponse<_REST_StylesetHashInfo> rj = Client.Execute<_REST_StylesetHashInfo>(Request);
return rj;
}
示例15: Create
public Models.Deployment Create(Stream depfile, string filename)
{
var request = new RestRequest("repository/deployments", Method.POST);
request.AddFile("deployfile", (s) => { depfile.CopyTo(s); }, filename);
var response = base.Client.Execute<Models.Deployment>(request);
base.HandleError(response);
return response.Data;
}