//below only allows images and pdf files to be uploaded. public override Stream GetStream(System.Net.Http.HttpContent parent, System.Net.Http.Headers.HttpContentHeaders headers) { // following line handles other form fields other than files. if (String.IsNullOrEmpty(headers.ContentDisposition.FileName)) { return(base.GetStream(parent, headers)); } // restrict what filetypes can be uploaded List <string> extensions = new List <string> { "png", "gif", "jpg", "jpeg", "tiff", "pdf", "tif", "bmp", "doc", "docx", "ods", "xls", "odt", "csv", "txt", "rtf" }; var filename = headers.ContentDisposition.FileName.Replace("\"", string.Empty); // correct for chrome. //make sure it has an extension if (filename.IndexOf('.') < 0) { return(Stream.Null); } //get the extension var extension = filename.Split('.').Last(); //Return stream if match otherwise return null stream. return(extensions.Contains(extension) ? base.GetStream(parent, headers) : Stream.Null); }
/*follow the logic in Java code from here...https://developer.walmart.com/#/apicenter/marketPlace/v2#getReport */ private async Task <string> parseResponse(Base.Http.IResponse response, string folderName) { System.Net.Http.Headers.HttpContentHeaders headers = response.RawResponse.Content.Headers; string fileDir = null; using (Stream inputStream = await response.RawResponse.Content.ReadAsStreamAsync()) { if ((response.StatusCode == System.Net.HttpStatusCode.OK) && (headers.ContentLength > 0)) { try { var header = headers.GetValues("Content-Disposition").First(); if ((header != null) && (!header.Equals(""))) { var length = header.Length; var start = header.IndexOf("filename="); var fileName = header.Substring(start, length - start); var str = fileName.Split('='); var dir = folderName + str[1]; using (Stream fileStream = new FileStream(dir, FileMode.Create, FileAccess.Write)) { inputStream.CopyTo(fileStream); } fileDir = dir; } } catch (System.Exception ex) { throw new Base.Exception.InvalidValueException("Error " + ex.Message); } } } return(fileDir); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { //string extension = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? Path.GetExtension(GetValidFileName(headers.ContentDisposition.FileName)) : ""; //string FileName = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? Path.GetFileName(GetValidFileName(headers.ContentDisposition.FileName)) : ""; //return Guid.NewGuid().ToString() + extension; return(FileName); }
/// <summary> /// Gets the name of the local file. /// </summary> /// <param name="headers">The headers.</param> /// <returns></returns> public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { string oldfileName = headers.ContentDisposition.FileName.Replace("\"", string.Empty); string newFileName = System.DateTime.Now.Ticks.ToString() + Path.GetExtension(oldfileName); return(newFileName); }
public override void OnWriteToStream(Type type, object value, Stream stream, System.Net.Http.Headers.HttpContentHeaders contentHeaders, System.Net.TransportContext context) { var output = (string)value; var writer = new StreamWriter(stream); writer.Write(output); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { // override the filename which is stored by the provider (by default is bodypart_x) string originalFileName = headers.ContentDisposition.FileName.Trim('\"'); return(originalFileName); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { var name = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? headers.ContentDisposition.FileName : "NoName"; //this is here because Chrome submits files in quotation marks which get treated as part of the filename and get escaped return(name.Replace("\"", string.Empty)); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { string originalFileName = headers.ContentDisposition.FileName.Trim('\"'); return(originalFileName); //return string.Concat(originalFileName, ".zip"); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { string fileNamePrefix = DateTime.Now.ToString("yyyyMMddHHmmssffff"); string fileName = string.Format(@"{0}.jpg", fileNamePrefix); return(fileName); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { OldName = JsonConvert.DeserializeObject(headers.ContentDisposition.FileName).ToString(); NewName = String.Format("{0}{1}", base.GetLocalFileName(headers), Path.GetExtension(OldName)); return(String.Format("{0}{1}", base.RootPath, OldName)); }
// Опис: Метод за екстракција и вчитување на име од локален фајл // Влезни параметри: HttpContentHeaders headers public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { var name = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? headers.ContentDisposition.FileName : "NoName"; return(name.Trim(new char[] { '"' }) .Replace("&", "and")); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { Logger.LogInfo("Upload File:" + Path.GetFileName(GetValidFileName(headers.ContentDisposition.FileName)).ToString(), "", ""); //string extension = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? Path.GetExtension(GetValidFileName(headers.ContentDisposition.FileName)) : ""; //return Guid.NewGuid().ToString() + extension; return(Path.GetFileName(GetValidFileName(headers.ContentDisposition.FileName))); }
// Summary: // Gets the name of the local file which will be combined with the root path // to create an absolute file name where the contents of the current MIME body // part will be stored. // 默认是guid作为文件名的.如果重载,那么可以制定一个有意义的文件名 // Parameters: // headers: // The headers for the current MIME body part. // Returns: // A relative filename with no path component. public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { var oldname = headers.ContentDisposition.FileName; var posible_full_name = (!string.IsNullOrWhiteSpace(oldname) ? oldname : "NoName").Replace("\"", string.Empty); var nicename = Path.GetFileNameWithoutExtension(posible_full_name); var nicenameExt = Path.GetExtension(posible_full_name); var hn = serverBase + posible_full_name; Random r = new Random(); int i = 0; while (File.Exists(hn)) { i++; posible_full_name = string.Format(nicename + "({0}{1}{2}-{3}{4}{5}-{6})" + nicenameExt, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, i); hn = serverBase + posible_full_name; } if (!fnmap.ContainsKey(oldname)) { fnmap.Add(oldname, new FileInfo(hn));//Authority + posible_full_name 图片 } return(posible_full_name); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { if (headers == null) { throw new NullReferenceException("headers cant be null"); } return(headers.ContentDisposition.FileName.Replace("\"", "")); }
private static void PrepareRequestDefaultHeader(this HttpClient httpClient, System.Net.Http.Headers.HttpContentHeaders contentHeaders) { if (contentHeaders != null) { contentHeaders.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); } }
// This method serializes a type by writing it to a stream. If your formatter supports deserialization, also override the ReadFromStream method. protected override Task OnWriteToStreamAsync( Type type, object value, System.IO.Stream stream, System.Net.Http.Headers.HttpContentHeaders contentHeaders, FormatterContext formatterContext, System.Net.TransportContext transportContext) { return(Task.Factory.StartNew(() => { WriteHigFormat(value, stream); })); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { //Make the file name URL safe and then use it & is the only disallowed url character allowed in a windows filename var name = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? headers.ContentDisposition.FileName : "NoName"; return(name.Trim(new char[] { '"' }) .Replace("&", "and")); }
public override System.IO.Stream GetStream(HttpContent parent, System.Net.Http.Headers.HttpContentHeaders headers) { var name = (headers.ContentDisposition.Name ?? "undefined").Replace("\"", "").Replace("\\", "_").Replace("/", "_").Replace("..", "_"); _startUpload(name); return(new WriteFileStreamProxy(Path.Combine(_rootPath, name), _uploadProgress)); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { //截取文件扩展名 string exp = Path.GetExtension(headers.ContentDisposition.FileName.TrimStart('"').TrimEnd('"')); string name = base.GetLocalFileName(headers); return(name + exp); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { // override the filename which is stored by the provider (by default is bodypart_x) string oldfileName = headers.ContentDisposition.FileName.Replace("\"", string.Empty); string newFileName = System.Guid.NewGuid().ToString() + Path.GetExtension(oldfileName); return(newFileName); }
public HttpContentHeaders(System.Net.Http.Headers.HttpContentHeaders containedObject) { if ((containedObject == null)) { throw new System.ArgumentNullException("containedObject"); } this.containedObject = containedObject; }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { string extension = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? Path.GetExtension(GetValidFileName(headers.ContentDisposition.FileName)) : ""; return(Guid + extension); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { var originalName = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? headers.ContentDisposition.FileName : "NoName"; originalName = originalName.Replace("\"", string.Empty); var name = originalName.Replace(originalName.Substring(0, originalName.IndexOf('.')), ScanId.ToString()); return(name); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { //Make the file name URL safe and then use it & is the only disallowed url character allowed in a windows filename var name = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? headers.ContentDisposition.FileName : "NoName"; var guid = Guid.NewGuid(); return(guid.ToString() + "." + name.Split('.').Last()); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { // override the filename which is stored by the provider (by default is bodypart_x) Guid g; g = Guid.NewGuid(); string originalFileName = g.ToString() + ".jpg"; return(originalFileName); }
public HttpContentHeaders() { var msg = new HttpRequestMessage { Content = new StringContent("abc", Encoding.UTF8, MediaTypeNames.Text.Plain) }; _headers = msg.Content.Headers; _headers.Add("existing_simple_header", "existing_value"); _headers.Add("existing_complex_header", new[] { "existing_value_01", "existing_value_02" }); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { // override the filename which is stored by the provider (by default is bodypart_x) string actualFileName = headers.ContentDisposition.FileName.Trim('\"'); var fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(actualFileName); var extension = System.IO.Path.GetExtension(actualFileName); var newFileName = $"{fileNameWithoutExtension}_{Guid.NewGuid().ToString().Substring(0, 8)}{extension}"; return(Regex.Replace(newFileName, @"[^a-zA-Z0-9_\.]", "-") ?.Trim('-')); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { //var name = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) // ? Guid.NewGuid() + "_" + headers.ContentDisposition.FileName // : "NoName"; string tempName = headers.ContentDisposition.FileName.Replace("\"", string.Empty); string fileExtension = Path.HasExtension(tempName) ? Path.GetExtension(tempName) : ".jpg"; return(Guid.NewGuid() + fileExtension); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { var name = !string.IsNullOrWhiteSpace(headers.ContentDisposition.FileName) ? headers.ContentDisposition.FileName : "NoName"; name = name.Replace("\"", string.Empty); //name = (Guid.NewGuid()).ToString() +System.IO.Path.GetExtension(name); //this is here because Chrome submits files in quotation marks which get treated as part of the filename and get escaped name = System.IO.Path.GetRandomFileName().Replace(".", string.Empty) + System.IO.Path.GetExtension(name); //this is here because Chrome submits files in quotation marks which get treated as part of the filename and get escaped return(name); }
public override string GetLocalFileName(System.Net.Http.Headers.HttpContentHeaders headers) { if (headers != null && headers.ContentDisposition != null) { return(headers .ContentDisposition .FileName.TrimEnd('"').TrimStart('"')); } return(base.GetLocalFileName(headers)); }